Senin, 30 April 2012

[MS_AccessPros] BeforeUpdate in subform cancels update when Close button on main form is clicked

 

Good afternoon or evening :-),

If the user is in the middle of entering data on a subform and decides to close the form using the Close button on the main form, the BeforeUpdate event of the subform gives the message that the something needs to be changed and cancels the update, but the DoCmd.Close continues so the form is closed with no opportunity to change the data.

Don't think you need it but here's the code behind the BeforeUpdate event.

'Prevent double entries for Me.Ordr = 1
If Me.Ordr = 1 Then
' Point to this database
Set db = CurrentDb
'Open ListingContacts to find priorities for this listing that are the same as Me.Priority
Set rstP = db.OpenRecordset("SELECT * FROM SalesBuyers " & _
"WHERE SaleID = " & Me.SaleID & " And Ordr = " & Me.Ordr)
If rstP.RecordCount > 0 Then
Msgbox "Another contact has this order." _
& vbNewLine & "Change the other contact's order and then enter this contact"
Me.Undo
End If
End If
'Clean Up
rstP.Close
Set rstP = Nothing
Set db = Nothing

Thanks!
Connie

__._,_.___
.

__,_._,___

Tidak ada komentar:

Posting Komentar