Hi PHV:
Thank you for your response. Actially I am populating a from through a query. I have written this code. My VBA is not very good. But when this code is executed I get this error "object required".
Through this code, I want the program to do the following:
Once the ID is entered on the "Search _Record _2" form the and the command button named Search is clicked the SQL statement pulls the information from table and depending upon any match it populates the correspondning controls on the form ("Serach_Record_2") that includes list boxes, combo boxes and text boxes.
Your inputs are appreciated.
Thanks in advance for your consideration.
Info
* PS-I do not know how to highlight the line of the code.
Private Sub Search_Click()
On Error GoTo Err_Command5_Click
Dim f As Form
Set f = Currentform.Form
Dim rs as ADODB.Recordset
set cn=new ADODB.Connection
strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=H:\special"
Cn.Open strCon
'open the recordset
Set rs = New ADODB.Recordset
rs.CursorType = adOpenKeyset
rs.LockType = adLockOptimistic
rs.CursorLocation = adUseClient
strSQL = "SELECT ID FROM Tracking_Table WHERE ID=" & Forms.Search_Record_2.Controls!ID & ";"
MsgBox (strSQL)
rs.Open strSQL, Cn, adOpenDynamic, adLockOptimistic
If (rs.EOF) Then
'Query returened empty. Quit and print the error message:
MsgBox ("Error: Cannot find The Ptient ID in the the Special procedures Tracking Table so exiting....")
Else
With f
If Not rs.EOF And Not rs.BOF Then
Do While Not rs.EOF
.ID = rs.Fields("ID").Value
.Text12 = rs.Fields("Date").Value
.List14 = rs.Fields("Typeprocedure").Value
.Text16 = rs.Fields("RoomNo").Value
.List18 = rs.Fields("Name").Value
.Combo20 = rs.Fields("Time_for").Value
Loop
End If
End With
rs.Close
End If
MsgBox (strSQL)
Cn.Close
Set Cn = Nothing
Exit_Command5_Click:
Exit Sub
Err_Command5_Click:
MsgBox Err.Description
Resume Exit_Command5_Click
Exit Sub
End Sub