Selasa, 02 Oktober 2012

Re: [MS_AccessPros] Prompt user whether they want to save changes when the form's close

 

Hello Mr. Peterson, thanks. It works great after I tried that in the Before Update Event. As a matter of fact the form in the production DB does not have a record source and all the controls (text box) are unbound.

What I've been using is the text box Enter Event (as shown below). But this triggers the message to dislay as soon as the value in the text box's changed. Users may feel Annoying if the message pops up every time for every text box they edit. It's the reason I try to look for an event that can trigger the message only after all editing was done and the user click the Close button on the form.

The Form.Dirty Event won't work, does it (I tried, it seems not...)?

Phucon.

Private Sub txtStaff_Enter()
On Error GoTo ErrorHandler
If IsNull(Me.cboStaff) Or Me.cboStaff = vbNullString Then
GoTo ExitProcedure
Else
Me.txtStaff = Me.cboStaff.Column(1)
Call Response
Me.cboStaff = ""
End If

ExitProcedure:
Exit Sub
ErrorHandler:
MsgBox Err & vbCrLf & Err.Description
Resume ExitProcedure
End Sub

Sub Response()
intResponse = MsgBox("Save changes? Yes/No", vbYesNo, "Save record")
If intResponse = vbYes Then
Call cmdSave_Click
ElseIf intResponse = vbNo Then
Call cmdUndo_Click
End If
End Sub

--- In MS_Access_Professionals@yahoogroups.com, "Robert Peterson" <bob@...> wrote:
>
> This code goes in the Before Update Event
>
> The Close Event happens after the update is completed so the form is not
> dirty anymore.
>
> Bob Peterson
>
>
> -----Original Message-----
> From: MS_Access_Professionals@yahoogroups.com
> [mailto:MS_Access_Professionals@yahoogroups.com] On Behalf Of saigonf7q5
> Sent: Tuesday, October 02, 2012 1:30 PM
> To: MS_Access_Professionals@yahoogroups.com
> Subject: [MS_AccessPros] Prompt user whether they want to save changes
> when the form's close
>
> I have been trying to display a message to ask the user whether they
> want to save changes they made to the record, before they close the
> form. I stepped through the Form_Close event, but the If Me.Dirty
> stament has never become true after the data in a control (text box) was
> changed? Why is that?
>
>
> Private Sub Form_Close()
> If Me.Dirty Then
> Call Response
> End If
> End Sub
>
> Sub Response()
> intResponse = MsgBox("Save changes? Yes/No", vbYesNo, "Save Record")
> If intResponse = vbYes Then
> Call SaveChanges
> ElseIf intReply = vbNo Then
> Call UndoTyping
> End If
> End Sub
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>

__._,_.___
Recent Activity:
.

__,_._,___

Tidak ada komentar:

Posting Komentar