| |||||||||
|
|
A Blue Claw Database Design Template: Airline Reservations Database Template |
Here is the VBA code behind the Save Account button. You can see how it save the record; requeries the combo boxes on the main form; fills in the newly entered values in the the main form and finally sets the focus to the Asset Class field.
Private Sub Command8_Click()
On Error GoTo Err_Command8_Click
DoCmd.RunCommand acCmdSaveRecord
Form_F_Trds_Unbnd.Accnt_Name_Entry.Requery
Form_F_Trds_Unbnd.Accnt_Number_Combo.Requery
'
Form_F_Trds_Unbnd.Accnt_ID = Me.Account_ID
Form_F_Trds_Unbnd.Accnt_Name_Entry = Me.Account_ID
Form_F_Trds_Unbnd.Accnt_Number_Combo = Me.Account_ID
DoCmd.Close
Form_F_Trds_Unbnd.Asset_class_Combo.SetFocus
Exit_Command8_Click:
Exit Sub
Err_Command8_Click:
MsgBox Err.Description
Resume Exit_Command8_Click
End Sub
Here is the main form again ready to continue data entry after handling the not in list event.

Below is the visual basic code used to immediately add the new list item to the lookup table:
Private Sub Combo20_NotInList(newdata As String, Response As Integer)
Response = acDataErrContinue
Call Drug_Not_Found(newdata)
End Sub
Public Sub Drug_Not_Found(newdata)
Dim ans As Variant
' new drug name
gbl_exit_name = False
ans = MsgBox("Do you want to add this drug?", _
vbYesNo, "Add New drug?")
If ans = vbNo Then
Me.Combo20 = Null
DoCmd.GoToControl "dosage"
GoTo exit_it
End If
' add drug name
DoCmd.RunSQL ("INSERT INTO L_Drugs ( Drug ) SELECT '" & newdata & "'")
Me.Combo20 = Null
Me.Combo20.Requery
Me.Combo20 = DLookup("Drug_id", "L_Drugs", "Drug='" & newdata & "'")
DoCmd.GoToControl "Dosage"
exit_it:
|
A Blue Claw Database Design Template: Construction Project Software |
|
A Blue Claw Database Design Article: Computer Disaster Recovery Planning |
|
|