silvrerado
Technical User
I got a main form that is used to input data and a popup dialog to search the record in the main form. In the popup dialog box I have a unbound txtVehNo and txtJobNo textbox to search the main form to display the found record. Apparently the code I'm using is not working properly since it said "Record found!" but the main form record is not showing the record that was found instead it shows the last record of the table. The code is found below. Can anyone assist. I'm very new to VBA.
Private Sub btnFind_Click()
Dim rt As DAO.Recordset, TOkay As Boolean
Set rt = CurrentDb.OpenRecordset("Tbl_JobInvoiceAdvice"
If rt.EOF And rt.BOF Then
MsgBox "There are no records in the Job Invoice Advice Table"
Exit Sub
End If
If IsNull(Me.txtVehNo) Then Exit Sub
TOkay = False
rt.MoveLast
rt.MoveFirst
Do While Not rt.EOF
If Me.txtVehNo = rt![VehNo] Then
TOkay = True
Forms!Frm_JobInvoiceAdvice.cboVehNo = Me.txtVehNo
Exit Do
End If
rt.MoveNext
Loop
If TOkay Then
MsgBox "The Record found!"
Else
MsgBox "Record not found!"
End If
rt.Close
Set rt = Nothing
End Sub
Thxs
silvre
Private Sub btnFind_Click()
Dim rt As DAO.Recordset, TOkay As Boolean
Set rt = CurrentDb.OpenRecordset("Tbl_JobInvoiceAdvice"
If rt.EOF And rt.BOF Then
MsgBox "There are no records in the Job Invoice Advice Table"
Exit Sub
End If
If IsNull(Me.txtVehNo) Then Exit Sub
TOkay = False
rt.MoveLast
rt.MoveFirst
Do While Not rt.EOF
If Me.txtVehNo = rt![VehNo] Then
TOkay = True
Forms!Frm_JobInvoiceAdvice.cboVehNo = Me.txtVehNo
Exit Do
End If
rt.MoveNext
Loop
If TOkay Then
MsgBox "The Record found!"
Else
MsgBox "Record not found!"
End If
rt.Close
Set rt = Nothing
End Sub
Thxs
silvre