Hello, I have been trying to work a little with VBA and have run into one issue so far with dates.
Right now my form has a drop down combo box and in the combo box you select a worker and it gives that combo box a unique value associated to selected worker. Next I have a text box to enter a date you would like to assign to the worker you selected. Finally you click the button to add this date to two tables where the selected workers unique id matches. One table is just a running log of all dates ever assigned to a worker and the other table is just the most current date assigned. Below is my current code for the button to make this happen.
Code:
Option Compare Database
Private Sub Add_Augment_Click()
If IsNull(Me.Input_Staff) Then
MsgBox "Staff Member needs an entry!"
Cancel = True
Input_Staff.SetFocus
ElseIf IsNull(Me.Input_Date) Then
MsgBox "Date needs an entry!"
Cancel = True
Input_Date.SetFocus
Else
Dim Aug_Date As String
Aug_Date = DLookup("Augment_Date", "Staff_List", "WORKERID = ([Input_Staff].Value)")
If Me.Input_Date.value <= Aug_Date Then
DoCmd.RunSQL "INSERT INTO Augmentation_Dates (WORKERID, Augment_Date) VALUES (([Input_Staff].Value), ([Input_Date].Value))"
Me.Input_Staff.value = Null
Me.Input_Date.value = Null
Else
DoCmd.RunSQL "UPDATE Staff_List SET Augment_Date = ([Input_Date].Value) WHERE WORKERID = ([Input_Staff].Value)"
DoCmd.RunSQL "INSERT INTO Augmentation_Dates (WORKERID, Augment_Date) VALUES (([Input_Staff].Value), ([Input_Date].Value))"
Me.Input_Staff.value = Null
Me.Input_Date.value = Null
End If
End If
End Sub
The purpose of this setup currently is so the Staff_List date only ever displays the most current date entered for any given worker. So if JOHN has a most recent date(Augment_Date) of 8/27/2020 and you try to enter 8/26/2020 for him, it will still make a entry no matter what in the Aumentation_Dates table but it would not update his most current date in the Staff_List table as I want that to stay the most recent date assigned.
The issue I am running into is currently I have JOHN with is most recent Augment_Date of 10/1/2019. When I add a date from 2/1/2020 on it will update the date in the Staff_List as it should since it is a more current date, but if i enter a date in January of this year it does not update in the Staff_List as if 1/15/2020 is not more current than 10/1/2019. Could anyone assist me in figuring out as to why that would be happening? Also this is the first time I have tried messing with access so if someone could also maybe help me clean up my above code so it is proper I would appreciate it. Comparing the proper formatted code to mine would really help me learn a bit better. Thanks to all who help.