My Assistant
![]() ![]() |
|
|
Jan 25 2006, 12:33 PM
Post
#1
|
|
|
UtterAccess Addict Posts: 117 |
I would like to write some code and I can't seem to come up with a good structure.
Here's what I want to happen. When the submit button is pressed I would like If (There are any entries with Me.frmDate and Me.Employee in the TimeCard table) Prompt (Do you want to override current data?) if yes (delete all entries (2 entries) with specified data and replace with new entries) if no (do not update fields, but leave forms current position) Else (use INSERT INTO sql to enter Me.alltheentries into the table)<-This part is already programmed I know pretty well how to write the code incorporating sql into vba but I just am having a hard time wrapping my head around how to structure this. |
|
|
|
Jan 25 2006, 12:45 PM
Post
#2
|
|
|
UtterAccess VIP Posts: 9,209 From: Maryland |
Here some code that I use for one of my dbs to do what you are asking.
CODE Dim TechID As String Dim TotalHours As String Dim ProjectHours As String Dim HistoryMonth As String Dim Dup As String Dim ViewID As String Dim varWhere As Variant Dim QD As QueryDef Dim db As Database Dim rst As Recordset TechID = Me.TechID TotalHours = Me.HoursWorked ProjectHours = Me.ProjectHours HistoryMonth = Me.StartDate Me.PreviouslyEntered = Nz(DLookup("HistoryID", "tblHistory", "TechID =" & TechID & "AND HistoryMonth =#" & HistoryMonth & "#")) If IsNull(Me.PreviouslyEntered) Or Me.PreviouslyEntered = "" Then Dup = 0 Else Dup = Me.PreviouslyEntered End If If Me.PreviouslyEntered <> 0 Then Select Case MsgBox("Productivity Data has already been entered for this Tech for the month indicated!" & vbCrLf & _ "Do you want to REPLACE that Data with date currently entered?", vbYesNo + vbQuestion, "Already Entered") Case vbYes Set db = CurrentDb() db.Execute ("UPDATE tblHistory SET tblHistory.TotalHours = " & TotalHours & ", tblHistory.ProjectHours = " & ProjectHours & "," & _ " tblHistory.HistoryMonth = #" & HistoryMonth & "#" & _ " WHERE (((tblHistory.HistoryID)=" & Dup & "));") Case vbNo MsgBox "Please pull reports for unchanged data from the Tech Report Menu", vbInformation, "Incorrect Menu" DoCmd.OpenForm "frmTechReports", , , , , , Me.Name Me.Visible = False Exit Sub End Select Else Set db = CurrentDb() Set rst = db.OpenRecordset("tblHistory") rst.AddNew rst!TechID = TechID rst!TotalHours = TotalHours rst!ProjectHours = ProjectHours rst!HistoryMonth = HistoryMonth rst.Update rst.close Set rst = Nothing End If HTH. |
|
|
|
Jan 25 2006, 02:34 PM
Post
#3
|
|
|
UtterAccess Addict Posts: 117 |
cool
thats about right thanks |
|
|
|
Jan 25 2006, 03:09 PM
Post
#4
|
|
|
UtterAccess VIP Posts: 9,209 From: Maryland |
Glad I could help.
|
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 21st May 2013 - 06:42 AM |