Using a Form to open 2nd form

  • Thread starter Thread starter Guest
  • Start date Start date
Do you have a button that closes the form?
If so, it goes in the button's Click event, before the close.

If not, this issue does not apply. Access will give you the message when you
close the bound form.
 
I have a close command button at the bottom of the form. I add the code that
you suggested that I use but It still will not work. When I click on the
button it goes to the first form. It needs to give me an error msg. so that
the user can make the corrections. Here is the code that is in the click
event section:

Private Sub Close_Form_Click()
On Error GoTo Err_Close_Form_Click

If Me.Dirty Then
Me.Dirty = False
End If
DoCmd.Close acForm, Me.Name

Exit_Close_Form_Click:
Exit Sub

Err_Close_Form_Click:
MsgBox Err.Description
Resume Exit_Close_Form_Click

End Sub

Please tell me what I am doing wrong.

Thanks you again for all your help.

Robin
 
You have already set up the Form_BeforeUpdate event so that it complains if
a required field is left blank. That means it is impossible to save the form
once an entry has been started unless the required field is filled in.

Setting Dirty to False fires Form_BeforeUpdate if there is any entry in
progress. That takes care of the required field.

The only other scenario is where the user has *not* even started any entry.
This usually means they changed their mind and decided no to make an entry.
The normal process would be to accept that there is no entry at all and
allow them to close the form. If you want to insist that they MUST enter a
record, and they cannot close the form until they do so, you could add a
condition that tests to see if they are still at the new record, and don't
allow the close for that case.

It does not seem like a good idea to me, but the code would look like this:

Private Sub Close_Form_Click()
On Error GoTo Err_Close_Form_Click

If Me.Dirty Then
Me.Dirty = False
End If
If Me.NewRecord Then
MsgBox "You cannot get outa here until you enter something!"
Else
DoCmd.Close acForm, Me.Name
End If

Exit_Close_Form_Click:
Exit Sub

Err_Close_Form_Click:
MsgBox Err.Description
Resume Exit_Close_Form_Click
End Sub

You would need to make the form modal, and turn off its Close button and
Control Box to make this reliable.
 
Back
Top