I have a client contact information form which requires the user to enter details about the tennis player.
I want to ensure the user enters the name of the new player on the form and for the user to not be able to exit the form unless a playername is entered.
I have the following code on the before update and on exit of the control to ensure that a user cannot tab to the next textbox unless data is entered:
Private Sub playername_BeforeUpdate(Cancel As Integer)
If IsNull(Me.[PlayerName]) = True Or Len(Me.[PlayerName]) < 1 Then
MsgBox "You must enter the Player's name!", vbOK, "Tennis Center Business Manager 2007"
Cancel = True
End If
End Sub
I have kind of sorted this out but there is one problem.
I have command button on the same form that using the on click event checks to see if the playername is null (ie empty) and then if it is not empty closes the form. However if the playername has had data entered and then deleted for whatever reason, my on click code does not see the text box as empty and closes the form against my wish without showing the msgbox I want to appear. Here is my on click vba code:
Private Sub OLEUnbound199_Click()
If Len(Me.[PlayerName]) = O Or IsNull(Me.PlayerName) = True Or Nz(Me.PlayerName) Then
MsgBox "You must enter the Player's name!", vbOK, "Tennis Center Business Manager 2007"
Cancel = True
Exit Sub
End If
DoCmd.OpenForm "Switchboard", acNormal
DoCmd.Close acForm, "Client Information", acSaveYes
I want to ensure the user enters the name of the new player on the form and for the user to not be able to exit the form unless a playername is entered.
I have the following code on the before update and on exit of the control to ensure that a user cannot tab to the next textbox unless data is entered:
Private Sub playername_BeforeUpdate(Cancel As Integer)
If IsNull(Me.[PlayerName]) = True Or Len(Me.[PlayerName]) < 1 Then
MsgBox "You must enter the Player's name!", vbOK, "Tennis Center Business Manager 2007"
Cancel = True
End If
End Sub
I have kind of sorted this out but there is one problem.
I have command button on the same form that using the on click event checks to see if the playername is null (ie empty) and then if it is not empty closes the form. However if the playername has had data entered and then deleted for whatever reason, my on click code does not see the text box as empty and closes the form against my wish without showing the msgbox I want to appear. Here is my on click vba code:
Private Sub OLEUnbound199_Click()
If Len(Me.[PlayerName]) = O Or IsNull(Me.PlayerName) = True Or Nz(Me.PlayerName) Then
MsgBox "You must enter the Player's name!", vbOK, "Tennis Center Business Manager 2007"
Cancel = True
Exit Sub
End If
DoCmd.OpenForm "Switchboard", acNormal
DoCmd.Close acForm, "Client Information", acSaveYes