OnClick and MsgBox -> Little Understanding

snagrat

Registered User.
Local time
Today, 13:32
Joined
Apr 2, 2002
Messages
61
I have a command button on my form.

At the moment the only code on the button is DoCmd.Close (and the other error handling code).

When the button is clicked I want the following to occur:
  • Check txtSurname and txtFirstName
  • If contain no data then msgbox(No data in required fields click canel to exit saving no data, or retry to return to form)
  • If all fields contain data then close form

Hope you can understand that.

Any help would be great as I am rubbish at this VBA stuff.
 
What you need to do is setup an if statement to check things

If IsNull(txtSurname) or IsNull(txtFirstName) Then

MsgBox "Type a message here",vbYesNo

Exit Sub

End If

Docmd.Close

If no data is there it will give the message and skip the close command.
 
Thats works fine, but if there is a problem then I get a Yes/No box.

I want a Cancel/Retry which I know how to do.

But if the Cancel button is clicked I want the msgbox to close and the form.

any if the retry is licked then i just want the msgbox to close

cheers for that though :)
 
Well the msgbox doesn't offer retry.

What you can do is ask them if they want to retry then press yes, if not no.

Then set this up:

If IsNull(txtSurname) or IsNull(txtFirstName) Then

If MsgBox ("Type a message here",vbYesNo)= vbYes then

exit sub

End if

End if

If they press no then it will continue with the code and close the form.
 
If you put vbRetryCancel instead of vbYesNo then you get Retry and Cancel on the form.

I will try and figure the rest out
 
Really? In all my programming I've never noticed that option. :(
 

Users who are viewing this thread

Back
Top Bottom