I am running a search on my database and evrything works, but when I try to view the next record I get a message Variable not set.
I am running Vb6 with access 97. I put the part of code that is giving me trouble in bold.....please help.
Code:
Option Explicit
Dim SQL As String
Private oDatabase As ADODB.Connection 'this is the connection
Private oRS As ADODB.Recordset 'this is the recordset
Private Sub cmdSearch_Click()
Dim sSearchText As String
Dim Clientname As String
Dim oDatabase As ADODB.Connection: Set oDatabase = New ADODB.Connection
Dim oRS As ADODB.Recordset: Set oRS = New ADODB.Recordset
List1.Clear
List2.Clear
sSearchText = txtSearch
lblSearch.Visible = True
MousePointer = vbHourglass
With oDatabase
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Data Source=" & App.Path & "\KJV.mdb"
.Open
End With
Set oRS = New ADODB.Recordset
oRS.Open "BibleTable", oDatabase, adOpenKeyset, adLockPessimistic, adCmdTable 'opening the recordset
oRS.Filter = "[TextData] LIKE '%" & sSearchText & "%'"
oRS.Open "SELECT * from BibleTable WHERE [TextData] LIKE '%" & sSearchText & "%'", oDatabase, adOpenForwardOnly, adLockReadOnly
If oRS.EOF Then
MsgBox "No record found matching "
Else
oRS.MoveFirst
End If
List1.Clear
List2.Clear
Do Until oRS.EOF
List1.AddItem (oRS.Fields(4))
List2.AddItem (oRS.Fields(1))
oRS.MoveNext
Loop
If Not (oRS.BOF = True) Then
oRS.MoveFirst
If oRS.BOF = True Then
MsgBox "Records Found"
Else
txtBookTitle = oRS.Fields("BookTitle")
txtChapter = oRS.Fields("Chapter")
txtVerse = oRS.Fields("Verse")
txtData = oRS.Fields("TextData")
End If
List1.Visible = True
List2.Visible = True
cmdReset.Visible = True
End If
End Sub
Private Sub cmdNext_Click()
If Not (oRS.EOF = True) Then
oRS.MoveNext
If oRS.BOF = True Then
MsgBox "You are at the first Verse", vbExclamation, "Holy Bible KJV"
Exit Sub
Else
txtBookTitle = oRS.Fields("BookTitle")
txtChapter = oRS.Fields("Chapter")
txtVerse = oRS.Fields("Verse")
txtData = oRS.Fields("TextData")
End If
End Sub