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!

Field Validation in Form_Close()

Status
Not open for further replies.

Prog76

Programmer
Oct 2, 2003
32
0
0
US
I am checking for required fields in the OnClose function and if there is a field missing I want the Close function to stop. It just keeps closing on me. This is what I have:

If Me!txtReqNum <> "" Then
If IsNull(Me!optionReason) Then
MsgBox ("Please enter a reason for the status change.")
Me!optionReason.SetFocus
Exit Sub
End If

End If
 
Try this
Code:
Private Sub Form_Close(Cancel As Boolean)
If Me!txtReqNum <> "" Then
    If IsNull(Me!optionReason) Then
        MsgBox ("Please enter a reason for the status change.")
        Me!optionReason.SetFocus
        Cancel = True
        Exit Sub
    End If
Cancel = False     
End If
End Sub
 
I tried that and I got an error when I compiled:

"Procedure declaration does not match description of event or procedure having the same name
 
How are ya Prog76 . . . . .

Right Idea . . . . [blue]Wrong Event![/blue] The [blue]Close Event[/blue] does not use the [purple]Cancel Arguement[/purple] (you can't cancel the Close Event).

You wand the [purple]On Unload[/purple] event!

Calvin.gif
See Ya! . . . . . .
 
Does that mean no data validation in the Close event????
 
Prog76 said:
[blue]Does that mean no data validation in the Close event????[/blue]
Yes it does, but since [blue]you can't cancel/roll back the Close event[/blue] . . . . whats the point?

Just move the code to the [blue]UnLoad[/blue] event. Your validation will be done there. In the normal sequence of events, the [blue]UnLoad[/blue] event occurs first, then the [blue]Close[/blue] event.

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top