M
Misty30706
Help!!!!
I have a form that is UNBOUND. I need to have the application ask the user if
he/she wants to save changes before closing, if the user made changes to the
data.
OK, I have a pretty good start. The code below actually works as specified
(for the most part) What happens is, sometimes, the user gets prompted even
if NO changes have been made! This usually happens after the user has added a
new record.
While this is certainly not a critical error (the user either hits yes or no
then the form closes), it is annoying!
Can anyone see anything wrong with my code?
To give a little bit more background....when the form opens, a boolean value:
blnAddNew is set to false. When a user wants to add a new record (as opposed
to updating an existing record) the user clicks a button that clears the form
and sets the blnAddNew to True. Once the user is finished adding the new
record, he/she hits save, the save adds a new record to the table(s) (code is
..AddNew then at the end... .update .close), then sets the blnAddNew back to
false. Then, when closing the form, the following code is run:
Dim strMsg As String
plngCustomer_No = NumCustomerID
If TxtCustomerLastName <> Nz(DLookup("[CustomerLastName]",
"TblCustomerInfo", "[CustomerID] =" & [plngCustomer_No])) _
Or TxtCustomerFirstName <> Nz(DLookup("[CustomerFirstName]",
"TblCustomerInfo", "[CustomerID] =" & [plngCustomer_No])) _
Or TxtCustomerMiddleInt <> Nz(DLookup("[CustomerMiddleInt]",
"TblCustomerInfo", "[CustomerID] =" & [plngCustomer_No])) _
Or TxtCustomerAddress <> Nz(DLookup("[CustomerAddress]",
"TblCustomerInfo", "[CustomerID] =" & [plngCustomer_No])) _
Or TxtCustomerAddress2 <> Nz(DLookup("[CustomerAddress2]",
"TblCustomerInfo", "[CustomerID] =" & [plngCustomer_No])) _
Or TxtCustomerCity <> Nz(DLookup("[CustomerCity]", "TblCustomerInfo",
"[CustomerID] =" & [plngCustomer_No])) _
Or CboCustomerState <> Nz(DLookup("[CustomerState]", "TblCustomerInfo",
"[CustomerID] =" & [plngCustomer_No])) _
Or TxtCustomerZip <> Nz(DLookup("[CustomerZip]", "TblCustomerInfo",
"[CustomerID] =" & [plngCustomer_No])) _
Or TxtCustomerPhone <> Nz(DLookup("[CustomerPhone]", "TblCustomerInfo",
"[CustomerID] =" & [plngCustomer_No])) _
Or TxtCustomerDOB <> Nz(DLookup("[CustomerDOB]", "TblCustomerInfo",
"[CustomerID] =" & [plngCustomer_No])) _
Or TxtCustomerAge <> Nz(DLookup("[CustomerAge]", "TblCustomerInfo",
"[CustomerID] =" & [plngCustomer_No])) _
Or CboCustomerGender <> Nz(DLookup("[CustomerGender]",
"TblCustomerInfo", "[CustomerID] =" & [plngCustomer_No])) _
Or IsNull(Me.NumCustomerID) Then
strMsg = "Changes have not been saved?"
strMsg = strMsg & vbCr & " Click Yes to save changes now."
strMsg = strMsg & vbCr & " Click No to close the form without
saving."
If MsgBox(strMsg, vbQuestion + vbYesNo, "Save changes now?") =
vbYes Then
If blnAddNew = True Then
Call SaveNewCustomer
Else
Call EditExistingCustomer
End If
End If
End If
DoCmd.Close
Obviously my formatting has been all muffed up, but hopefully you get the
picture. It is at this point the my pop-up box comes up asking the user if
he/she wants to save the changes - even if no changes have been made! What is
so aggravating is that this only happens after adding a new record (but this
also makes it not very critical, just annoying).
So does anyone see anything wrong with my code that would cause this problem to
happen? Or does anyone have a simpler way to do this?
Thanks so much for any help you can offer!
Brenda
I have a form that is UNBOUND. I need to have the application ask the user if
he/she wants to save changes before closing, if the user made changes to the
data.
OK, I have a pretty good start. The code below actually works as specified
(for the most part) What happens is, sometimes, the user gets prompted even
if NO changes have been made! This usually happens after the user has added a
new record.
While this is certainly not a critical error (the user either hits yes or no
then the form closes), it is annoying!
Can anyone see anything wrong with my code?
To give a little bit more background....when the form opens, a boolean value:
blnAddNew is set to false. When a user wants to add a new record (as opposed
to updating an existing record) the user clicks a button that clears the form
and sets the blnAddNew to True. Once the user is finished adding the new
record, he/she hits save, the save adds a new record to the table(s) (code is
..AddNew then at the end... .update .close), then sets the blnAddNew back to
false. Then, when closing the form, the following code is run:
Dim strMsg As String
plngCustomer_No = NumCustomerID
If TxtCustomerLastName <> Nz(DLookup("[CustomerLastName]",
"TblCustomerInfo", "[CustomerID] =" & [plngCustomer_No])) _
Or TxtCustomerFirstName <> Nz(DLookup("[CustomerFirstName]",
"TblCustomerInfo", "[CustomerID] =" & [plngCustomer_No])) _
Or TxtCustomerMiddleInt <> Nz(DLookup("[CustomerMiddleInt]",
"TblCustomerInfo", "[CustomerID] =" & [plngCustomer_No])) _
Or TxtCustomerAddress <> Nz(DLookup("[CustomerAddress]",
"TblCustomerInfo", "[CustomerID] =" & [plngCustomer_No])) _
Or TxtCustomerAddress2 <> Nz(DLookup("[CustomerAddress2]",
"TblCustomerInfo", "[CustomerID] =" & [plngCustomer_No])) _
Or TxtCustomerCity <> Nz(DLookup("[CustomerCity]", "TblCustomerInfo",
"[CustomerID] =" & [plngCustomer_No])) _
Or CboCustomerState <> Nz(DLookup("[CustomerState]", "TblCustomerInfo",
"[CustomerID] =" & [plngCustomer_No])) _
Or TxtCustomerZip <> Nz(DLookup("[CustomerZip]", "TblCustomerInfo",
"[CustomerID] =" & [plngCustomer_No])) _
Or TxtCustomerPhone <> Nz(DLookup("[CustomerPhone]", "TblCustomerInfo",
"[CustomerID] =" & [plngCustomer_No])) _
Or TxtCustomerDOB <> Nz(DLookup("[CustomerDOB]", "TblCustomerInfo",
"[CustomerID] =" & [plngCustomer_No])) _
Or TxtCustomerAge <> Nz(DLookup("[CustomerAge]", "TblCustomerInfo",
"[CustomerID] =" & [plngCustomer_No])) _
Or CboCustomerGender <> Nz(DLookup("[CustomerGender]",
"TblCustomerInfo", "[CustomerID] =" & [plngCustomer_No])) _
Or IsNull(Me.NumCustomerID) Then
strMsg = "Changes have not been saved?"
strMsg = strMsg & vbCr & " Click Yes to save changes now."
strMsg = strMsg & vbCr & " Click No to close the form without
saving."
If MsgBox(strMsg, vbQuestion + vbYesNo, "Save changes now?") =
vbYes Then
If blnAddNew = True Then
Call SaveNewCustomer
Else
Call EditExistingCustomer
End If
End If
End If
DoCmd.Close
Obviously my formatting has been all muffed up, but hopefully you get the
picture. It is at this point the my pop-up box comes up asking the user if
he/she wants to save the changes - even if no changes have been made! What is
so aggravating is that this only happens after adding a new record (but this
also makes it not very critical, just annoying).
So does anyone see anything wrong with my code that would cause this problem to
happen? Or does anyone have a simpler way to do this?
Thanks so much for any help you can offer!
Brenda