Save and Close command buttons

F

FA

I have two command bottons on the forms
1)
Private Sub Save_Click()
Dim Answer As Integer

Answer = MsgBox("Are you sure you want to save this record?", 36,
"Enter New Record ")
If Answer = vbYes Then
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70
End If
2)
Private Sub Close_Click()
On Error GoTo Err_Command94_Click
DoCmd.Close

Exit_Command94_Click:
Exit Sub
Err_Command94_Click:
MsgBox Err.Description
Resume Exit_Command94_Click

I want to have a functionality where if user add/update record and
click the Close command button without clicking the Save command
botton, it should prompt the user if he/she wants to save the record.
If the user click the save command button after adding/updating a
record and hit the close command button, then they should not be asked
to save the record.

Any help would be greatly appreciated.

Thanks
 
G

Guest

from Rainbow01 Hong Kong

from my develop access database's experiences, i suggest :
1) Set your form not to display the close icon in right hand top side i.e.
"X", this can force the user to click command button if want to close the form
2) if user want to save record ( include edit old record or add new record),
just click SAVE button and then close the form
3) if user want to abort saving ( include edit old record or add new
record), just click CLOSE button and then close the form

for step2: Docmd.Runcommand acSaveRecord
Docmd.Close acForm, Me.Name
for step3: If Me.Dirty = True Then
If MsgBox("Are you sure want to abort saving?") = vbYes
Then
Me.Undo
Docmd.Close acForm, Me.Name
End If
Else
Docmd.Close acForm, Me.Name
End If




"FA" 來函:
 

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