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
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)
Emiliano F. Martín
If a post has helped you then pleaseRate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
If a post has helped you then pleaseRate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
Originally posted by Mc Brain A tip... for everybody. Try avoidin using
VB Code:
Dim variable As New VariableType
Use this instead:
VB Code:
Dim variable As VariableType
Set variable = New VariableType
Declaring variables As a new instance of an object, forces the compiler to control in each operation if the object has been previously created. So... this is what your "compiled code" would look like (Everyone know that it won't look like that... but it will be coded as if this is the source of your program)
Emiliano F. Martín
If a post has helped you then pleaseRate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.