ifNull textbox OkayCancel Message

CraigDouglas

Registered User.
Local time
Today, 17:20
Joined
Sep 14, 2016
Messages
31
Please can someone help? I have a form frmAddNewCustomer. I have a text box in it called txtCustomerEmail. When the form closes, I want a message to come up if there is no email in the txtCustomerEmail text box. I want to have two options in the msgBox one to cancel the closing of the form if the person forgot to put the email address in. So, they can go and put it in and an option to continue to close the form and go back to the frmOrderForm that will be open as the frmAddNewCustomer opened from the frmOrderForm. The message will be something like click cancel to fill in the email address or click ok to continue. I tried all different things and the best code I could come up with is wrong but I will paste it.

The other problem I have is I already have code in the Close event. I will attach my Database. Craig

Code:
On Error GoTo ErrorHandler
If (IsNull(txtCustomerEmail)) Then
        Beep
        MsgBox "Don't forget email address if possible.", vbOKCancel, "Warning!"
 ElseIf vbOK Then
    DoCmd.Close

            End If
CleanUpAndExit:

    Exit Sub

ErrorHandler:
Call MsgBox("An error was encountered" & vbCrLf & vbCrLf & _
            "Description: " & Err.Description & vbCrLf & _
            "Error Number: " & Err.Number, , "Error")

    Resume CleanUpAndExit
 

Attachments

In my view the best place to validate data is the before update event of the form:

Thank you for your help. The code does work but an error message comes up: Error
An Error was encountered
Description: No current record
No: 3021

I also had to take the Me.refresh out of the one bit of code otherwise the message appears straight after I paste in the CustomerFullName text box. I can live with these problems though at least the code does what I wanted. I appreciate the help. Craig
 

Users who are viewing this thread

Back
Top Bottom