Problem Closing Forms.

J

John Ortt

Hi everyone,

I am having trouble closing forms with a button on the form.

This is specifically happening when the form has no data to display.

I have copied my code below.

Any help will be gratefully recieved.

Thanks in advance,

John.

------------------------------------------------------

Private Sub cmdClose_Click()

DoCmd.Close

End Sub


Function cmdGlobalClose_Click(stDocName As String)

Forms(stDocName).SetFocus
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.Close , , acSaveNo
DoCmd.Maximize

End Function
 
A

Allen Browne

You should be able to close it like this:

Function cmdGlobalClose_Click(stDocName As String)
If Forms(stDocName).Dirty Then
Forms(stDocName).Dirty = False
End If
DoCmd.Close acForm, stDocName , acSaveNo
End Function

Add error handling to cover the cases where:
- the form has no Dirty property (i.e. it is unbound),
- setting Dirty fails (i.e. the record cannot be saved.)
 
J

John Ortt

Lovely, I'll give it a try.

Thanks Allen

Allen Browne said:
You should be able to close it like this:

Function cmdGlobalClose_Click(stDocName As String)
If Forms(stDocName).Dirty Then
Forms(stDocName).Dirty = False
End If
DoCmd.Close acForm, stDocName , acSaveNo
End Function

Add error handling to cover the cases where:
- the form has no Dirty property (i.e. it is unbound),
- setting Dirty fails (i.e. the record cannot be saved.)
 

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