Hi everyone!
I've been creating an MS Access database to store info on venues, courses, students, assessors, and enrolments. I've completed the database itself but as part of my assignment I need to add an improvement at the end and I chose to add a label that shows the user how many fields they have left to add in the form. The save button also responds to this and unlocks once all required fields have been added. My issue is that the VBA I am using is not responding to the EnrolmentDate field, but instead wants the user to click on the EnrolmentID field (which is an AutoNumber PK). The other two required fields, StudentID and CourseID, respond properly. Here's the VBA used in the form's On Current:
Code:
Private Sub CourseID_AfterUpdate()
' Populate AssessorID based on the selected CourseID
Me.txtAssessorID.Value = DLookup("AssessorID", "Courses", "CourseID=" & Me.CourseID.Value)
Call UpdateProgress
End Sub
Private Sub CourseID_Click()
End Sub
Private Sub Form_Current()
Call UpdateProgress
End Sub
Private Sub UpdateProgress() Dim TotalFields As Integer
Dim FilledFields As Integer
Dim RemainingFields As Integer
' Set the total number of fields (exclude EnrolmentID and Achieved)
TotalFields = 3 ' Adjust based on required fields
' Check required fields
If Nz(Me.StudentID, 0) <> 0 Then FilledFields = FilledFields + 1 ' Combo box
If Nz(Me.CourseID, 0) <> 0 Then FilledFields = FilledFields + 1 ' Combo box
If Not IsNull(Me.EnrolmentDate) And Me.EnrolmentDate >= Date Then FilledFields = FilledFields + 1
' Date field
' Calculate remaining fields
RemainingFields = TotalFields - FilledFields
Debug.Print "Filled: " & FilledFields & " | Remaining: " & RemainingFields
' Update label
If RemainingFields > 0 Then
Me.lblRemainingFields.Caption = RemainingFields & " field(s) remaining"
Else
Me.lblRemainingFields.Caption = "All fields complete!"
End If
' Enable Save button only when all fields are complete
Me.Command20.Enabled = (RemainingFields = 0)
End Sub
Private Sub StudentID_AfterUpdate()
Call UpdateProgress
End Sub
Private Sub EnrolmentDate_AfterUpdate()
Call UpdateProgress
End Sub