pop-up confirmation message when changing a record

lala

Registered User.
Local time
Today, 17:43
Joined
Mar 20, 2002
Messages
741
how can I get a message box pop up each time a user changes anything in the record asking him if he's sure he wants to make changes to the record?

thank you
Lala

oh yea, i mean i want this message to come up each time the user leaves current record and goes to the next record or exits the forms (because each time the user goes to another record the previous record is automatically saved)
so I want to avoid this and give them an option of saving it or not
 
Last edited:
You'll want to search for the exact syntax and the appropriate event to use (I think it may be OnChange), but you'll want something in every control that OnChange does DoCmd.OpenForm(AreYouSureForm). The form will have a Yes and No button. Yes simply closes AreYouSureForm on click, No closes AreYouSureForm and does undo to the control. (I believe its DoCmd.Undo but I'm not positive).

Sorry I can't be more detailed, but this should get you on the right track.
 
thanks, but i was thinking doing it not field by field (because it'll be too much of a hastle to click yes on each field), but record by record

so my question is, where should i put the code for the message box to pop up after the user leaves the record?
 
You want the BeforeUpdate event. I know it's a shock, but searching the MS Access Help for "events" or "order of events" actually will help you understand *some* of the events and when they take place.

But BeforeUpdate for the form should pop the box up before any changes are saved. However, I'm not sure what the correct procedure is to return to the record when you hit No.
 
sweetie, if i had time to search the help database i wouldn't be asking here
but i have an hour to do this, and i can't spend the hour on looking through the help file
 
This took 35 seconds to find.

Moving the focus to records and updating data in records

When you move the focus to an existing record on a form, enter or change data in the record, and then move the focus to another record, the following sequence of events occurs for the form:

Current (form) Þ BeforeUpdate (form) Þ AfterUpdate (form) Þ Current (form)

When you leave the record whose data has changed, but before you enter the next record, the Exit and LostFocus events occur for the control with the focus. These events occur after the BeforeUpdate and AfterUpdate events for the form, as follows:

BeforeUpdate (form) Þ AfterUpdate (form) Þ Exit (control) Þ LostFocus (control) Þ RecordExit (form) Þ Current (form)

As you move the focus among the controls on a form, events occur for each control. For example, the following sequences of events occur when you:

Open a form and change data in a control:
Current (form) Þ Enter (control) Þ GotFocus (control) Þ BeforeUpdate (control) Þ AfterUpdate (control)

Move the focus to another control:
Exit (control1) Þ LostFocus (control1) Þ Enter (control2) Þ GotFocus (control2)

Move the focus to another record:
BeforeUpdate (form) Þ AfterUpdate (form) Þ Exit (control2) Þ LostFocus (control2) Þ RecordExit (form) Þ Current (form)
 
lala said:
sweetie, if i had time to search the help database i wouldn't be asking here
but i have an hour to do this, and i can't spend the hour on looking through the help file

Looks like your going to be in the $@#t then
 
Hi,

I am not sure this will help. But if you have time take a look on it. I have copy some where on the net but I can find the hyperlink. I didn't try it.

'
Adding Simple Validation...
Making Sure the User Fills In All the Fields
A Function to Pinpoint Missing Data
Here is an example of how you can write a piece of "generic" code to check that the form has been filled in. You could, of course, set the Required property of each field to Yes but this method involves less work and gives you the opportunity to display a friendly message and take the user straight to the appropriate field.
In the same code module as the form's event procedures, create the following custom function. You can enter it after the last of the event procedures:

Private Function CheckData() As Boolean
CheckData = True
Dim ctl As Control
Dim strName As String
For Each ctl In Me.Controls
If IsNull(ctl) Then
strName = ctl.Controls(0).Caption
CheckData = False
MsgBox "Please fill in the " & Chr(34) & strName & Chr(34) & " field."
ctl.SetFocus
Exit Function
End If
Next ctl
End Function

How the Function Works
The CheckData function returns False if it finds an empty text box or True if it does not (hence its declaration as Boolean). The first line sets the value of the function to True. It uses a For... Next loop to look in turn at each control on the form. If no empty controls are found the function returns the value True.
If it comes across an empty control an If Statement is invoked in which it notes the control's Caption (i.e. the Caption property of the label of a text box) and sets the value of the function to false. It then displays a message box incorporating the control's caption telling the user which control is missing data. Finally it sets the focus of the form to that control by placing the user's cursor into the control. At this point the function exits so that the user can correct their input.

Applying the Function
To make use of the function, add the line:

If CheckData = False Then Exit Sub

as the first line of each of the Click event procedures for the three tabs. When the user clicks one of the tabs, before anything else happens, the function is evaluated. If it returns True (meaning that there are no empty fields) the rest of the Click event procedure runs. If it returns False the Click event procedure exits (i.e. is cancelled) and the user is shown a message and taken to the appropriate field.

Hope this will help.

Le
 
Check out my A better mouse trap? sample to see how I prevent a user from moving to another record or closing the form IF the current has beeen modified. The user is prompted to either save or undo their changes.
 
Looks like your going to be in the $@#t then

:D

There is a difference between being helpful and being used isn't there Rich.
 
This mouse trap is very helpful !!! Thanks,

Le
 
thanks to everyone with helpful posts
cuz i see there are some kuku's here trying to be cute
haha

anyway
the mousetrap is good, but i'd rather the user get a messagebox with YES and NO buttons on it, so that he can click YES or NO to save or drop his changes

going back to the record is a solution, but i like for my databases to be as perfect as possible

anyone can help?
thanks!!!!!!!
 
Last edited:
Rich said:
Look up the MsgBox function


i will
but will that help me for this problem?
i don't think it will, if i understand msgboxes correctly

but i'll go look
 
Try this,

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
strMsg = "Data has changed."
strMsg = strMsg & " Do you wish to save the changes?"

If MsgBox(strMsg, vbQuestion + vbYesNo, "Save Record?") = vbYes Then
'do nothing
Else
DoCmd.RunCommand acCmdUndo

'For Access 95, use DoMenuItem instead
'DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
End If

End Sub

Ant.
 
Rich said:
or Me.Undo

Hi,

I don't think that Lala wants. I think she wants is check all the data before exit the form and the form has serveral fields. Correct me if I'm wrong.

Regards,

Le
 
le888 said:
Hi,

I don't think that Lala wants. I think she wants is check all the data before exit the form and the form has serveral fields. Correct me if I'm wrong.

Regards,

Le


What else could this mean, if there's no option to undo what's the point in asking users?

how can I get a message box pop up each time a user changes anything in the record asking him if he's sure he wants to make changes to the record?
 
She has wrote this :

Lala said:
thanks, but i was thinking doing it not field by field (because it'll be too much of a hastle to click yes on each field), but record by record

so my question is, where should i put the code for the message box to pop up after the user leaves the record?

Regards,
Le
 

Users who are viewing this thread

Back
Top Bottom