Problem returning Recordset
Hi
I am trying to return a recordset from a function in a class back to my form in order to display the data.
Code is as follows:
In my Form -
Dim bs as New Bookstore
Public rsResult = New ADODB.Recordset
Private Sub mnuBook_Click()
Dim strIsbn As String
strIsbn = InputBox("Enter the ISBN", "Search by ISBN")
If strIsbn = "" Then
MsgBox "No ISBN entered", vbOKOnly, "Search"
Else
Showdata(bs.findbyIsbn(strIsbn))
End If
End Sub
Private Sub Showdata(rsResult As ADODB.Recordset)
txtIsbn.Text = rsResult.Fields("ISBN")
(...display into all my other text boxes....)
End Sub
and in my Bookstore Class:
Public Function findbyIsbn(strIsbn As String) As ADODB.Recordset
Dim rsResult As New ADODB.Recordset
Dim strSQL As String
strSQL = "SELECT Author.*, Books.* FROM Author INNER JOIN Books ON Author.[Author Code] = Books.[Author Code] WHERE (Books.ISBN)='" & strIsbn & "';"
rsResult.Open strSQL, mcon1, adOpenDynamic, adLockOptimistic
Set findbyIsbn = rsResult
End Function
The problem is I get a Type Mismatch error on the - Showdata(bs.findbyIsbn(strIsbn)) - line of code in my form
Its probably something really simply, but I fairly new to VB and any advice would be appreciated
Cheers
Re: Problem returning Recordset
Quote:
Originally posted by mickysavage
Hi
I am trying to return a recordset from a function in a class back to my form in order to display the data.
Code is as follows:
In my Form -
Dim bs as New Bookstore
Public rsResult = New ADODB.Recordset
Private Sub mnuBook_Click()
Dim strIsbn As String
strIsbn = InputBox("Enter the ISBN", "Search by ISBN")
If strIsbn = "" Then
MsgBox "No ISBN entered", vbOKOnly, "Search"
Else
Showdata(bs.findbyIsbn(strIsbn))
End If
End Sub
Private Sub Showdata(rsResult As ADODB.Recordset)
txtIsbn.Text = rsResult.Fields("ISBN")
(...display into all my other text boxes....)
End Sub
and in my Bookstore Class:
Public Function findbyIsbn(strIsbn As String) As ADODB.Recordset
Dim rsResult As New ADODB.Recordset
Dim strSQL As String
strSQL = "SELECT Author.*, Books.* FROM Author INNER JOIN Books ON Author.[Author Code] = Books.[Author Code] WHERE (Books.ISBN)='" & strIsbn & "';"
rsResult.Open strSQL, mcon1, adOpenDynamic, adLockOptimistic
Set findbyIsbn = rsResult
End Function
The problem is I get a Type Mismatch error on the - Showdata(bs.findbyIsbn(strIsbn)) - line of code in my form
Its probably something really simply, but I fairly new to VB and any advice would be appreciated
Cheers
First of al... get rid of the parenthesis:
VB Code:
Showdata bs.findbyIsbn(strIsbn)