Msgbox syntax help

wizcow

Registered User.
Local time
Yesterday, 23:40
Joined
Sep 22, 2001
Messages
236
Hi

I want to have a message pop up when a certain text box is not filled in. I want the msgbox to give the option of 'Retry' then vb will put the focus on the empty text box. If the 'Cancel' button is clicked, then the form will close and not store the record.

This is the code I am wroking on and it just closes the form, no matter what button I click. Please let me know if you see what I have missed.

Private Sub Form_Unload(Cancel As Integer)

If IsNull(ISBN = "") Then
If vbRetry = MsgBox("Make an entry in the 'ISBN'." , 53, "Error Handler") Then
DoCmd.GoToControl "ISBN"
Exit Sub
End If
Cancel = True
DoCmd.Close
End If

End Sub
 
Dim Response As Integer

Response = MsgBox("Make an entry in the 'ISBN'", vbInformation + vbRetryCancel + vbDefaultButton1, "Missing Data")

If Response = vbRetry Then ' (Default)
Cancel = True
Me.ISBN.SetFocus
Else 'vbCancel
Me.Undo
Cancel = True
DoCmd.Close acForm "FormName"
End If

Put the code in the Forms Before Update event.


[This message has been edited by Jack Cowley (edited 04-07-2002).]
 
The message box comes up fine, but it fires even if there is an entry in 'ISBN' and it hangs on the

DoCmd.Close asForm "FormName"

every time. I entered the actual form name (frmBook). I also tried entering my first line again

If IsNull(ISBN = "") Then
ElseIf Response... etc.

but to no avail.
Thanks
Tom
 
My apologies... I forgot this line of code:

If IsNull(Me![ISBN]) Or Me![ISBN] = "" Then
 
The line

DoCmd.Close asForm "FormName"

gives an "Expected: end of statment" error
I put a comma at the end of 'asForm' but it still hangs up on this line.

Is this right?

Tom
 
That is better, but the program is still hanging up on that line.

[This message has been edited by wizcow (edited 04-07-2002).]
 
You didn't explain what hangs on this line actually meant. I suspect your getting a message "You can't carry out this operation", etc. If that's the case you have to move the focus away from your form. Instead of DoCmd. Close open a hidden form which closes the first and then closes itself.
 
What happens is the debugger starts and the line that is hi-lighted is the "close" command.
I tried the extra form idea and still the debugger starts when the code comes to the line that closes the first form.
 

Users who are viewing this thread

Back
Top Bottom