Type Mismatch

G

Guest

I don't understand why I'm getting a "Type Mismatch" with this code.
The only value I'm using is the "ICNNO"
I'm trying to transfer data to a report with: select * from [q_LetterVals]
where [ICNNo] = " & "'" & txtICNNO & "';")

Suggestions???


Dim stDocName As String
Dim stLinkCriteria As String
Dim dbcurrent As Database
Dim rstemp As Recordset

stLinkCriteria = "[ICNNO]=" & "'" & txtICNNO & "'"

If IsNull(Me.txtICNNO) Or Me.txtICNNO = "" Then
MsgBox "Please enter an ICNNO number"
Exit Sub
End If


Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from [q_LetterVals] where
[ICNNo] = " & "'" & txtICNNO & "';")
stDocName = "rptThankYou"
If rstemp.RecordCount > 0 Then
DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria
Exit Sub
End If

If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number. Please review and
try again"
txtICNNO.SetFocus
Exit Sub
End If
 
G

Guest

Are you sure that ICNNo is of Text data type?
If not, remove the single quotes.

Steve
 
G

Guest

Just a minor syntax problem:
select * from [q_LetterVals] where [ICNNo] = " & "'" & txtICNNO & "';")
try
select * from [q_LetterVals] where [ICNNo] = '" & txtICNNO & "';"
 
D

Dirk Goldgar

In
Dan @BCBS said:
I don't understand why I'm getting a "Type Mismatch" with this code.
The only value I'm using is the "ICNNO"
I'm trying to transfer data to a report with: select * from
[q_LetterVals] where [ICNNo] = " & "'" & txtICNNO & "';")

Suggestions???


Dim stDocName As String
Dim stLinkCriteria As String
Dim dbcurrent As Database
Dim rstemp As Recordset

stLinkCriteria = "[ICNNO]=" & "'" & txtICNNO & "'"

If IsNull(Me.txtICNNO) Or Me.txtICNNO = "" Then
MsgBox "Please enter an ICNNO number"
Exit Sub
End If


Set dbcurrent = CurrentDb
Set rstemp = CurrentDb.OpenRecordset("select * from [q_LetterVals]
where [ICNNo] = " & "'" & txtICNNO & "';")
stDocName = "rptThankYou"
If rstemp.RecordCount > 0 Then
DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria
Exit Sub
End If

If rstemp.RecordCount <= 0 Then
MsgBox "There is no record for this ICN Number. Please review
and try again"
txtICNNO.SetFocus
Exit Sub
End If

What version of Access are you using? Does it work if you declare the
recordset like this:

Dim rstemp As DAO.Recordset

?

In any case, you should close that recordset before you exit the
procedure.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

ADD Mode 4
User Defined 3
Object dosent support this property or method 2
Add record and update List 5
Type Mismatch 2
Type Mismatch 2
Type Mismatch 2
Open based on two values 4

Top