Fran,
For example you updated an Invoice Number of your vendor you purchased supplies. This sample would be PO (Purchase Order) system.
You have three tables. One is PO. Two Voucher tables, one is VN and the other is VN_Details.
This will be on the field Invoice_No AfterUpdate:
=Invoice_No_AfterUpdate()
Your VBA code event function will be as follows:
-------------------------------------------------
Public Function Invoice_No_AfterUpdate()
On Error GoTo Invoice_No_AfterUpdate_Err
Dim rstUpdRec As New ADODB.Recordset
Dim sqlUpdRec As String
Dim strID, strInvoice_No
strInvoice_No = Screen.ActiveForm.Invoice_No.Value
strID = Screen.ActiveForm.ID.Value
If IsNull(strID) Then
DoCmd.CancelEvent
ElseIf IsNull(strInvoice_No) Then
DoCmd.CancelEvent
Else
'--------------------------------'
' Update ID record on VN table '
'--------------------------------'
sqlUpdRec = "SELECT Invoice_No FROM VN "
sqlUpdRec = sqlUpdRec & "WHERE ID = """ & strID & """"
rstUpdRec.Open sqlUpdRec, CurrentProject.Connection, adOpenKeyset, adLockPessimistic
If rstUpdRec.EOF Then
rstUpdRec.Close
Set rstUpdRec = Nothing
Else
Do Until rstUpdRec.EOF
rstUpdRec("Invoice_No").Value = strInvoice_No
rstUpdRec.Update
rstUpdRec.MoveNext
Loop
rstUpdRec.Close
Set rstUpdRec = Nothing
End If
'----------------------------------------'
' Update ID record on VN_Details table '
'----------------------------------------'
sqlUpdRec = "SELECT Invoice_No FROM VN_Details "
sqlUpdRec = sqlUpdRec & "WHERE ID = """ & strID & """"
rstUpdRec.Open sqlUpdRec, CurrentProject.Connection, adOpenKeyset, adLockPessimistic
If rstUpdRec.EOF Then
rstUpdRec.Close
Set rstUpdRec = Nothing
Else
Do Until rstUpdRec.EOF
rstUpdRec("Invoice_No").Value = strInvoice_No
rstUpdRec.Update
rstUpdRec.MoveNext
Loop
rstUpdRec.Close
Set rstUpdRec = Nothing
End If
'--------------------------------'
' Update ID record on PO table '
'--------------------------------'
sqlUpdRec = "SELECT Invoice_No "
sqlUpdRec = sqlUpdRec & "FROM PO "
sqlUpdRec = sqlUpdRec & "WHERE ID = """ & strID & """"
rstUpdRec.Open sqlUpdRec, CurrentProject.Connection, adOpenKeyset, adLockPessimistic
If rstUpdRec.EOF Then
rstUpdRec.Close
Set rstUpdRec = Nothing
Else
rstUpdRec("Invoice_No").Value = strInvoice_No
rstUpdRec.Update
rstUpdRec.Close
Set rstUpdRec = Nothing
End If
End If
Invoice_No_AfterUpdate_Exit:
Exit Function
Invoice_No_AfterUpdate_Err:
MsgBox Err.Description
Resume Invoice_No_AfterUpdate_Exit
End Function
----------------------------------------------
Hope this helps.
John
|