PHV:
Thank you for your inputs.
If I have a list box can I transfer the results of a query to it? This is the code that I have so far:How do I tie in the results of the recordset with those of the entries for the list box that is there on the form that I am opening?
Regards,
Info
Private Sub Search_Click()
'On Error GoTo Err_Command2_Click
Dim cn As ADODB.Connection
' Dim cmdCommand As New ADODB.Command
Dim c As String
Dim rs As ADODB.Recordset
Dim strSQL As String
Dim strcon As String
Set cn = New ADODB.Connection
strcon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\p22841.NTGROUP\Desktop\lib.mdb"
'open the connection
'strcon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Desktop\lib.mdb"
'open the connection
cn.Open strcon
'create a new instance of the record set
Set rs = New ADODB.Recordset
rs.CursorType = adOpenKeyset
rs.LockType = adLockOptimistic
rs.CursorLocation = adUseClient
'display the message box that says that the search criteria is being looked for
If IsNull(Me.Text0) Then
Msg = " You have not entered any search criteria "
ans = MsgBox(Msg, vbYesNo)
If ans = vbNo Then
Exit Sub
Else
MsgBox "Please enter the search criteria for the directory search"
Exit Sub
End If
End If
If Not IsNull(Me.Text0) Then
strSQL = "SELECT * FROM directory WHERE last_name LIKE '" & Forms!Form1!Text0 & "%';"
'display the strSQL that goes with the SQL
MsgBox (strSQL)
'open the recordset
rs.Open strSQL, cn, adOpenDynamic, adLockOptimistic
If rs.BOF Or rs.EOF Then
MsgBox "There are no records in the database"
'disconnect the recordset
rs.Close
cn.Close
Set cn = Nothing
Exit Sub
End If
If Not rs.EOF And Not rs.BOF Then
c = rs.RecordCount
MsgBox (c)
DoCmd.OpenForm "search names"
End If
End If