Form closes anyway

T

TeeSee

I have the following aircode in the BeforeUpdate event of a form
opened in acFormEdit. When I click the close button it activates this
code. The messagebox shows up and when I click it the form closes
anyway. I thought the setfocus line would hold the form open. Any
thoughts? Thanks

If IsNull(Me!MyRequiredField) or Len(Trim(Me!MyRequiredField))=0 then
MsgBox "RequiredField must have a value."
MeMyRequiredField.SetFocus
Cancel = True
End If
 
J

John W. Vinson

I have the following aircode in the BeforeUpdate event of a form
opened in acFormEdit. When I click the close button it activates this
code. The messagebox shows up and when I click it the form closes
anyway. I thought the setfocus line would hold the form open. Any
thoughts? Thanks

If IsNull(Me!MyRequiredField) or Len(Trim(Me!MyRequiredField))=0 then
MsgBox "RequiredField must have a value."
MeMyRequiredField.SetFocus
Cancel = True
End If

The BeforeUpdate is being cancelled - it's not updating the record - but your
Close event isn't. What's the context? Could you post the code of the Close
button?
 
T

TeeSee

The BeforeUpdate is being cancelled - it's not updating the record - but your
Close event isn't. What's the context? Could you post the code of the Close
button?

John .... Thanks as always for responding. The following is the code
behind the cmdClose button

Private Sub cmdClose_Click()
On Error GoTo Err_cmdClose_Click

DoCmd.Close
Exit_cmdClose_Click:
Exit Sub

Err_cmdClose_Click:
MsgBox Err.Description
Resume Exit_cmdClose_Click

End Sub
 

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