Hi All,
I have a table with guest FN, LN and Acc#. I build the form to do the search, but it seems to be updating 1st records every time search is performed.
The way I wanted to work is when employee enters the Acc# and hits enter, it will show FN and LN in the box. My form is bound to the table. Form has three txtbox. 1st will be to enter Acc# and bound to the Acc# column, 2nd for FN, and bound to FN column, 3rd for LN, and bound to LN column. VBA code is set in FN txtbox "On Focus".
I would like users to be able to enter new records if it wasn't found.
Also, Acc is the Primary Key as I wanted to have a unique number.
New to VBA, still learning.
I have a table with guest FN, LN and Acc#. I build the form to do the search, but it seems to be updating 1st records every time search is performed.
The way I wanted to work is when employee enters the Acc# and hits enter, it will show FN and LN in the box. My form is bound to the table. Form has three txtbox. 1st will be to enter Acc# and bound to the Acc# column, 2nd for FN, and bound to FN column, 3rd for LN, and bound to LN column. VBA code is set in FN txtbox "On Focus".
I would like users to be able to enter new records if it wasn't found.
Also, Acc is the Primary Key as I wanted to have a unique number.
New to VBA, still learning.
Code:
Option Compare Database
Private Sub TxtCOCustFN_GotFocus()
Dim varX As String
Dim varY As String
Dim blnGood As Boolean
On Error GoTo Problem
varY = DLookup("FirstName", "TblCustomers", "AccNo = " & [Forms]![SubFrmCustSearch]![AccNo])
Me.TxtCustFN = varY
varX = DLookup("LastName", "TblCustomers","AccNo = " & [Forms]![SubFrmCustSearch]![AccNo])
Me.TxtCustLN = varX
Me.Requery
Exit Sub
Problem:
If Err.Number = 94 Then
Me.TxtCustFN = " "
Me.TxtCustLN = " "
MsgBox "Please Enter guest Name"
Call DoCmd.RunCommand(acCmdRecordsGoToNew)
End If
If Err.Number = 3022 Then
blnGood = True
Call DoCmd.RunCommand(acCmdSaveRecord)
blnGood = False
End If
End Sub
Last edited: