Save and Close Button Code Help

niccig

Registered User.
Local time
Today, 03:19
Joined
Sep 8, 2004
Messages
29
I'm new to VBA code.
I have a button on a form that will save the record and close the form. So far I have this code, it works, but I know it doesn't have any error handling.
Any input greatly appreciated.

Private Sub cmdSave_Click()
Set frm = Forms![frmhoursentry]
If Me.Dirty = True Then
DoCmd.RunCommand acCmdSaveRecord
End If

DoCmd.Close

End Sub
 
The record will save if you just close the form anyway, what are you trying to do with your code?
 
I'm just trying to close the form - it's a pop up window for a bit more data entry, and I want a prompt so they close it and go back to the main form.
 
Paste the code below on click command button. It will give you a pop up either save the record(go to new record) or cancel(undo).

Private Sub Command31_Click()
Dim strMsg As String, strTitle As String

strMsg = "Do You Want To Save This Record?"
strTitle = " Save Record ?"

If MsgBox(strMsg, vbQuestion + vbYesNo, strTitle) = vbNo Then
Me.Undo

End If

DoCmd.GoToRecord , , acNewRec

End Sub


If you want the form look more of a data entry. Go to form property:

Cycle= Current Record
Navigation Button = No

hth,

Michael
 
Along the same sort of lines, i am after some code.

When the close button is clicked i.e the one on the top right hand side of the screen is pops up with a message box saying do you want to save then the three options but i want it to open up as a 'save as' option showing the drive it wants to save it has.
Is this simple code or quite complicated
 
i am trying to use the example in my database.

when i change the data on my subform, the before update procedure does not register and the next record just changes without the msgbox coming up, am i missing something.
 

Users who are viewing this thread

Back
Top Bottom