Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dialog Box to Search on Main Form not working.

Status
Not open for further replies.

silvrerado

Technical User
Oct 1, 2003
6
SG
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
 
S,

Try changing this:

Forms!Frm_JobInvoiceAdvice.cboVehNo = Me.txtVehNo

to:

Forms!Frm_JobInvoiceAdvice.cboVehNo = rt![VehNo]


rollie@bwsys.net
 
Hi Rollie,

Only combo box shows the VehNo but the entire record did not display. Any other suggestion to get the entire record shown in the main form rather then the VehNo appears in the combo box?

Thxs again.

silvre
 
Silvre,
If all the fields in a cbo do not show, it is because the properties on number of fields is not correct and/or the width's of the various fields a not non-zero.

You can also move the various fields in a cbo by using the column property like

me.sometext = me.cbo1,column(?) where ? is the field position minus 1.

rollie@bwsys.net
 
Hi Rollie,

The combo box which was use to move the record is actually not what it is to be. It is a drop down list for selecting a VehNo and not a record finder. Apologise, since I'm new to VBA. The line below found in the routine should not be there but rather be deleted:

Forms!Frm_JobInvoiceAdvice.cboVehNo = Me.txtVehNo

The actual code was from this Forum which I found very good.
I inserted this code during the running of the code.

Is there any other code that need to be inserted or modify the above routine that will allow the routine to search and show the record found in the Main form.

Thxs


silvre
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top