G
Guest
I am fairly new to recordsets and have two different databases that I am
trying to get a search of tables to work. Having problem with both. I don't
know if it is kosher to ask for solution to two problems on one post or not.
Guess I will find out, huh.
The first problem occurs at the rst.open line of code & I don't know why.
Private Sub cmdFind_Click()
Dim rst As ADODB.Recordset
Dim strCriteria As String
Set rst = New ADODB.Recordset
strCriteria = InputBox("Enter word to find:", "Search")
'opens recordset to support all cursor and record movements
rst.CursorType = adOpenDynamic
rst.Open "tblWords2 ORDER by tblWords2.Word;", CurrentProject.Connection
strCriteria = rst.Fields(0)
With rst
rst.MoveFirst
Do While Not .EOF
rst.Find ("s = '" & strCriteria & "'")
rst.MoveNext
If rst.EOF Then
rst.Close
Exit Sub
End If
Loop
End With
The second database gets its input from a listbox and then I want to search
the database and show all records that meet that criteria. The error occurs
at the rst.Find ("s = '" & strCriteria & "'") line of code.
Private Sub cmdFindAlbum_Click()
Dim rst As ADODB.Recordset
Dim strCriteria As String
Set rst = New ADODB.Recordset
strCriteria = Me.lstTitle
rst.CursorType = adOpenDynamic 'opens recordset to support all cursor and
record movements
rst.Open "tblSongs ORDER BY tblSongs.Album;", CurrentProject.Connection
Debug.Print rst.State
Debug.Print Album
Dim s As String
s = rst.Fields(0)
With rst
rst.MoveFirst 'move to first rec
Do While Not .EOF
rst.Find ("s = '" & strCriteria & "'") 'locate correct rec
rst.MoveNext
If rst.EOF Then 'returns eof if no
match found
rst.Close
Exit Sub 'exit
End If 'else do this
Loop
End With
End Sub
Thank you all....
trying to get a search of tables to work. Having problem with both. I don't
know if it is kosher to ask for solution to two problems on one post or not.
Guess I will find out, huh.
The first problem occurs at the rst.open line of code & I don't know why.
Private Sub cmdFind_Click()
Dim rst As ADODB.Recordset
Dim strCriteria As String
Set rst = New ADODB.Recordset
strCriteria = InputBox("Enter word to find:", "Search")
'opens recordset to support all cursor and record movements
rst.CursorType = adOpenDynamic
rst.Open "tblWords2 ORDER by tblWords2.Word;", CurrentProject.Connection
strCriteria = rst.Fields(0)
With rst
rst.MoveFirst
Do While Not .EOF
rst.Find ("s = '" & strCriteria & "'")
rst.MoveNext
If rst.EOF Then
rst.Close
Exit Sub
End If
Loop
End With
The second database gets its input from a listbox and then I want to search
the database and show all records that meet that criteria. The error occurs
at the rst.Find ("s = '" & strCriteria & "'") line of code.
Private Sub cmdFindAlbum_Click()
Dim rst As ADODB.Recordset
Dim strCriteria As String
Set rst = New ADODB.Recordset
strCriteria = Me.lstTitle
rst.CursorType = adOpenDynamic 'opens recordset to support all cursor and
record movements
rst.Open "tblSongs ORDER BY tblSongs.Album;", CurrentProject.Connection
Debug.Print rst.State
Debug.Print Album
Dim s As String
s = rst.Fields(0)
With rst
rst.MoveFirst 'move to first rec
Do While Not .EOF
rst.Find ("s = '" & strCriteria & "'") 'locate correct rec
rst.MoveNext
If rst.EOF Then 'returns eof if no
match found
rst.Close
Exit Sub 'exit
End If 'else do this
Loop
End With
End Sub
Thank you all....