Code:
Private Sub Form_Current()
Dim todaydate As Date
Dim masl1 As Date
Dim masl2 As Date
Dim masl3 As Date
todaydate = Date
masl1 = gradONE.Value
masl2 = gradTWO.Value
masl3 = gradTHR.Value
If IsEmpty(masl1) Then masl1 = todaydate - 100 Else todaydate = Date
If IsEmpty(masl2) Then masl2 = todaydate - 100 Else todaydate = Date
If IsEmpty(masl3) Then masl3 = todaydate - 100 Else todaydate = Date
Select Case todaydate
Case Is < masl1
Text70.Value = DLookup("COURSE_NAME", "Courses_Info", "MASL = maslONEtxt")
Text72.Value = DLookup("COURSE_ID", "Courses_Info", "MASL = maslONEtxt")
Text74.Value = DLookup("SQUADRON", "Courses_Info", "MASL = maslONEtxt")
Text76.Value = DLookup("BUILDING", "Courses_Info", "MASL = maslONEtxt")
Text78.Value = DLookup("PH_EXT", "Courses_Info", "MASL = maslONEtxt")
Text80.Value = DLookup("RM", "Courses_Info", "MASL = maslONEtxt")
Text84.Value = DLookup("SHIFT", "Courses_Info", "MASL = maslONEtxt")
Text91.Value = DLookup("TIME", "Courses_Info", "MASL = maslONEtxt")
Case Is < masl2
Text70.Value = DLookup("COURSE_NAME", "Courses_Info", "MASL = maslTWOtxt")
Text72.Value = DLookup("COURSE_ID", "Courses_Info", "MASL = maslTWOtxt")
Text74.Value = DLookup("SQUADRON", "Courses_Info", "MASL = maslTWOtxt")
Text76.Value = DLookup("BUILDING", "Courses_Info", "MASL = maslTWOtxt")
Text78.Value = DLookup("PH_EXT", "Courses_Info", "MASL = maslTWOtxt")
Text80.Value = DLookup("RM", "Courses_Info", "MASL = maslTWOtxt")
Text84.Value = DLookup("SHIFT", "Courses_Info", "MASL = maslTWOtxt")
Text91.Value = DLookup("TIME", "Courses_Info", "MASL = maslTWOtxt")
Case Is < masl3
Text70.Value = DLookup("COURSE_NAME", "Courses_Info", "MASL = maslTHRtxt")
Text72.Value = DLookup("COURSE_ID", "Courses_Info", "MASL = maslTHRtxt")
Text74.Value = DLookup("SQUADRON", "Courses_Info", "MASL = maslTHRtxt")
Text76.Value = DLookup("BUILDING", "Courses_Info", "MASL = maslTHRtxt")
Text78.Value = DLookup("PH_EXT", "Courses_Info", "MASL = maslTHRtxt")
Text80.Value = DLookup("RM", "Courses_Info", "MASL = maslTHRtxt")
Text84.Value = DLookup("SHIFT", "Courses_Info", "MASL = maslTHRtxt")
Text91.Value = DLookup("TIME", "Courses_Info", "MASL = maslTHRtxt")
Case Else
Text70.Value = "Unknown"
Text72.Value = "Unknown"
Text74.Value = "Unknown"
Text76.Value = "Unknown"
Text78.Value = "Unknown"
Text80.Value = "Unknown"
Text84.Value = "Unknown"
Text91.Value = "Unknown"
End Select
End Sub
I'm using the code above to attempt to populate unbound fields based on three date boxes. It populates those fields based on which of the three dates is closest to today's date (except those that have passed).
The issue with the code, which is the issue I've had with vba and access time and time again, is that i cannot seem to populate nulled variables so that they meet the requirements of the "Case Else." In fact, the code doesn't want to populate the variables if the date fields are empty/null at all. Any expertise would be of great benefit to me. I can't wait to learn how to deal with these things in all cases.
Thank you in advance for your help.
Last edited: