Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Required text code in form's Before Update NOT WORKING properly 1

Status
Not open for further replies.
Aug 4, 2004
84
0
0
US
Hello I have the following code in my forms before update in order to check if there is text in the field:

If IsNull(Confirmed) Then
MsgBox "Data is required."
Confirmed.SetFocus
Cancel = True
End If

However, when I exit my form via the close form button, a message says:

"data entry required" which is great, I click ok to enter text but the form closes???

The confirmed field is a required field in the table properties, However, a message box only comes up when you physically click on the field and TAB out of it. If you click on the Field and click out the message does not come up and you can close the form...

any Suggestions???
 
Check for the required field as part of the code behind the close button. If it isn't there, don't allow the form to be closed. Something like.....

Private Sub cmdClose_Click()
Dim strSQL As String
Dim intButtons As Integer
Dim strTitle As String
strSQL = "Confirmed is a required field."
intButtons = vbCritical + vbOkOnly
strTitle = "Required Data Missing"
If IsNull(txtConfirmed) or txtConfirmed = "" Then
MsgBox strSQL, intButtons, strTitle
Else
DoCmd.Close
End If
End Sub


Randy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top