Problem with close button

M

Merwin12

I have two buttons, save and add new record.

If I make changes without saving, then msg pops up if I
want to change it then the form close.

If I make changes, save it then click close then form
won't close.

If I add a new record, even though I did not make any
changes, it adds a new blank record, then closes the form.

If I add a new record and Me.dirty = true, then
form 'won't close.

Please help.

code behind close button:
Dim Cancel As Integer
Dim msg, style, Title, response As String
Static blnsave As Boolean

msg = "Do you want to save your changes ?" ' Define
message.
style = vbYesNo + vbDefaultButton1 ' Define buttons.
Title = "Confirm Save" ' Define title.


If IsFormLoaded("frmPhonelog") = True And Not IsNull
(Me.Org_seqno) And Not blnsave Then
If Me.Dirty = True Then
response = MsgBox(msg, style, Title)
If response = vbNo Then
Cancel = True
Me.Undo
blnsave = False
DoCmd.CLOSE
Exit Sub
Else 'save your changes
Call cmdSave_Click
blnsave = True
DoCmd.CLOSE
End If
Else
If Me.Dirty = False And Me.NewRecord = True And Not
blnsave Then
Cancel = True
Me.Undo
DoCmd.CLOSE
End If
End If
Else
DoCmd.CLOSE

End If



Thanks.
 

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