VB Coding Assistance

B

Bunky

I am a novice coder trying to learn VB OJT and I am getting no where. I have
a form that the client enters data to go onto the table. I always want the
client to enter certain pieces of data then I validate it through VB code.
My problem right now is that I have made the form dirty and then have a
procedure that occurs beforeupdate event. If the client clicks on the Cancel
and Exit button without saving, I get a message that the client must enter
the user. On clicking on 'OK' it exits as it should but I cannot get it to
quit that display of the msgbox.

The click on the Cancel runs this code.
Private Sub Command56_Click()
DoCmd.CancelEvent
DoCmd.Close
End Sub

and the Before update runs this code.




Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_BUForm_Click

If IsNull(Me.User) Then

MsgBox "Please Enter a Specialistbu."
Me.User.SetFocus
Cancel = True
GoTo Exit_BUForm_Click
End If


If IsNull(Me.AttendDate) Then
MsgBox "Please Enter a valid Datebu."
Me.AttendDate.SetFocus
Cancel = True
GoTo Exit_BUForm_Click
End If

If IsNull(Me.Comments) Then
MsgBox "Please Enter Commentsbu."
Me.Comments.SetFocus
Cancel = True
GoTo Exit_BUForm_Click
End If

Exit_BUForm_Click:
Exit Sub

Err_BUForm_Click:
MsgBox Err.Description
Resume Exit_BUForm_Click
End Sub

Any suggestions will be appreciated greatly!
 
D

Douglas J. Steele

See whether this works any better:

Private Sub Command56_Click()
Me.Undo
DoCmd.Close
End Sub

You might need Me.Undo twice.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top