Minggu, 23 Desember 2012

[MS_AccessPros] Help with new record before Update

 

Hi All,
I must not quite understand the BeforeUpdate event. The process I am trying to perform is as follows: When the current record is changed, I want to display a message to verify the change. If the record is new, then display message to save new record. These messages are to be displayed when the current record is changed (moving from the change/new record to another record of form). The code I am trying to use is below. Currently when I select to add a new record using navigation controls the event fires when the first control has first character inputted, after that when moving to another record the event does not trigger. The record is created without displaying message. I was hoping to display prior to moving off the record.

Rod

Private Sub Form_BeforeInsert(Cancel As Integer)
'If the form data has changed a message is shown asking if
'the changes should be saved. If the answer is no then
'the changes are undone

On Error GoTo BeforeUpdate_Error

If Me.Dirty Then
If Me.NewRecord Then
Me.lngTPTID = GetTPTID()
'if new record has been added then Display a message
' to save the record
If MsgBox("Do you want to save this new record?", _
vbYesNo + vbQuestion, "Save Record") = vbNo Then
Me.Undo
End If
Else
'if record has been changed the dirty property
' is set to true Display message to save the record
If MsgBox("The record has changed - do you want to save t?", _
vbYesNo + vbQuestion, "Save Changes") = vbNo Then
Me.Undo
End If
End If
End If

BeforeUpdate_Exit:
Exit Sub

BeforeUpdate_Error:
MsgBox Err.Description
Resume BeforeUpdate_Exit

End Sub

__._,_.___
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (1)
Recent Activity:
.

__,_._,___

Tidak ada komentar:

Posting Komentar