Hi all. I have a form that i wish only to open if a particular criteria is met. The code i have got so far is as follows:
Private Sub OpenTraineeDetailsBtn_Click()
MsgBox Me.NumOnCourse
MsgBox Me.Location.Column(2)
If (Me.NumOnCourse < Me.Location.Column(2)) Then
On Error GoTo Err_OpenTraineeDetailsBtn_Click
Dim stDocName As String
Dim stLinkCriteria As String
DoCmd.GoToRecord , , acNext
DoCmd.GoToRecord , , acPrevious
stDocName = "Trainee_Details_FM"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_OpenTraineeDetailsBtn_Click:
Exit Sub
Err_OpenTraineeDetailsBtn_Click:
MsgBox Err.Description
Resume Exit_OpenTraineeDetailsBtn_Click
Else
MsgBox "No More Trainees Allowed On Course"
End If
End Sub
The initial messgae boxes output the correct values so i know my variables are correct in the if statement. The Statement however always opens the form, Even when the NumOnCourse is greater than Column 2 in the location combobox (this is the capacity of a location). I was hoping someone could pick the fault in my code as to why it seems to be ignoring the else part of the statement
This may help. When looking at the VB debugger the value in the NumOnCourse is not within "". Where as the column value is in quotes. is there a way i can get them both the same.
Thanks in advance.
Private Sub OpenTraineeDetailsBtn_Click()
MsgBox Me.NumOnCourse
MsgBox Me.Location.Column(2)
If (Me.NumOnCourse < Me.Location.Column(2)) Then
On Error GoTo Err_OpenTraineeDetailsBtn_Click
Dim stDocName As String
Dim stLinkCriteria As String
DoCmd.GoToRecord , , acNext
DoCmd.GoToRecord , , acPrevious
stDocName = "Trainee_Details_FM"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_OpenTraineeDetailsBtn_Click:
Exit Sub
Err_OpenTraineeDetailsBtn_Click:
MsgBox Err.Description
Resume Exit_OpenTraineeDetailsBtn_Click
Else
MsgBox "No More Trainees Allowed On Course"
End If
End Sub
The initial messgae boxes output the correct values so i know my variables are correct in the if statement. The Statement however always opens the form, Even when the NumOnCourse is greater than Column 2 in the location combobox (this is the capacity of a location). I was hoping someone could pick the fault in my code as to why it seems to be ignoring the else part of the statement
This may help. When looking at the VB debugger the value in the NumOnCourse is not within "". Where as the column value is in quotes. is there a way i can get them both the same.
Thanks in advance.
Last edited: