N
Neal Ostrander
I am trying to learn how to uses class modules in access 07. I have the
following code and it is giving me a Data type mismatch in criteria
expression.
Thanks in advance for any help
Neal
Dim value As String
value = InputBox("Enter ISBN to search for.", "Find Book")
newBook.FindBook value
End Sub
******************** below is in class module
Public Sub FindBook(ByVal value As String)
'declare variables
Dim bookID As String
Dim rsBook As New ADODB.Recordset
Dim strSQL As String
'assign value entered by user to bookID variable
bookID = value
'build sql string based on value entered by user
strSQL = "SELECT * FROM Books WHERE ISBN = " & bookID
'open recordset using the sql string
rsBook.Open strSQL, CurrentProject.AccessConnection, adOpenDynamic,
adLockOptimistic 'error occurs here
'if not eof assign values to global variables
If rsBook.EOF = False Then
bookTitle = rsBook!title
bookISBN = rsBook!isbn
bookDate = rsBook!PublishDate
bookPrice = rsBook!price
End If
'close recordset
rsBook.Close
MsgBox "Title: " & bookTitle & Chr(13) & "ISBN: " & bookISBN & Chr(13) &
"Published: " & bookDate & Chr(13) & "Price: " & bookPrice
End Sub
following code and it is giving me a Data type mismatch in criteria
expression.
Thanks in advance for any help
Neal
Dim value As String
value = InputBox("Enter ISBN to search for.", "Find Book")
newBook.FindBook value
End Sub
******************** below is in class module
Public Sub FindBook(ByVal value As String)
'declare variables
Dim bookID As String
Dim rsBook As New ADODB.Recordset
Dim strSQL As String
'assign value entered by user to bookID variable
bookID = value
'build sql string based on value entered by user
strSQL = "SELECT * FROM Books WHERE ISBN = " & bookID
'open recordset using the sql string
rsBook.Open strSQL, CurrentProject.AccessConnection, adOpenDynamic,
adLockOptimistic 'error occurs here
'if not eof assign values to global variables
If rsBook.EOF = False Then
bookTitle = rsBook!title
bookISBN = rsBook!isbn
bookDate = rsBook!PublishDate
bookPrice = rsBook!price
End If
'close recordset
rsBook.Close
MsgBox "Title: " & bookTitle & Chr(13) & "ISBN: " & bookISBN & Chr(13) &
"Published: " & bookDate & Chr(13) & "Price: " & bookPrice
End Sub