PC Review


Reply
Thread Tools Rate Thread

"data type mismatch" when printing report from form

 
 
Kyle
Guest
Posts: n/a
 
      16th Jan 2007
I have a form on which I placed a button that allows me to print the
page of the report for the record displayed in the form. When I click
on the button to print the report page, I get the error "data type
mismatch in criteria expression". I'm not sure where my code is
failing, but I know it's in the code; what am I missing?:

Private Sub Print_Memo_Click()
On Error GoTo Err_Print_Memo_Click

Dim stDocName As String

Dim strRecID As String
strRecID = "[Event_ID]='" & Me![Event_ID] & "'"

stDocName = "rpt_Detail_Request_Memo"
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport stDocName, acPreview, , strRecID
DoCmd.PrintOut acPages, 1, 1

Exit_Print_Memo_Click:
Exit Sub

Err_Print_Memo_Click:
MsgBox Err.Description
Resume Exit_Print_Memo_Click

End Sub


Many thanks for any and all help!

 
Reply With Quote
 
 
 
 
fredg
Guest
Posts: n/a
 
      16th Jan 2007
On 16 Jan 2007 14:02:08 -0800, Kyle wrote:

> I have a form on which I placed a button that allows me to print the
> page of the report for the record displayed in the form. When I click
> on the button to print the report page, I get the error "data type
> mismatch in criteria expression". I'm not sure where my code is
> failing, but I know it's in the code; what am I missing?:
>
> Private Sub Print_Memo_Click()
> On Error GoTo Err_Print_Memo_Click
>
> Dim stDocName As String
>
> Dim strRecID As String
> strRecID = "[Event_ID]='" & Me![Event_ID] & "'"
>
> stDocName = "rpt_Detail_Request_Memo"
> DoCmd.RunCommand acCmdSaveRecord
> DoCmd.OpenReport stDocName, acPreview, , strRecID
> DoCmd.PrintOut acPages, 1, 1
>
> Exit_Print_Memo_Click:
> Exit Sub
>
> Err_Print_Memo_Click:
> MsgBox Err.Description
> Resume Exit_Print_Memo_Click
>
> End Sub
>
> Many thanks for any and all help!


What is the datatype of the [Event_ID] field?
You have written the code as though it was Text datatype, but I
suspect [Event_ID] is Number datatype.

strRecID = "[Event_ID]=" & Me![Event_ID]


--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
 
Reply With Quote
 
Kyle
Guest
Posts: n/a
 
      17th Jan 2007
> What is the datatype of the [Event_ID] field?
> You have written the code as though it was Text datatype, but I
> suspect [Event_ID] is Number datatype.
>
> strRecID = "[Event_ID]=" & Me![Event_ID]


Yep, that's the problem. Event_ID is an autonumbering field which keeps
each event request as a unique record in the database (since we have
repeating events).

I really do need to keep that field as a number field rather than a
text field. How would I change it so it's no longer a string type?

This is what I get for copying the code from another database I
received help on last year, and not completely understanding the code.

Thanks!

 
Reply With Quote
 
fredg
Guest
Posts: n/a
 
      17th Jan 2007
On 17 Jan 2007 06:47:58 -0800, Kyle wrote:

>> What is the datatype of the [Event_ID] field?
>> You have written the code as though it was Text datatype, but I
>> suspect [Event_ID] is Number datatype.
>>
>> strRecID = "[Event_ID]=" & Me![Event_ID]

>
> Yep, that's the problem. Event_ID is an autonumbering field which keeps
> each event request as a unique record in the database (since we have
> repeating events).
>
> I really do need to keep that field as a number field rather than a
> text field. How would I change it so it's no longer a string type?
>
> This is what I get for copying the code from another database I
> received help on last year, and not completely understanding the code.
>
> Thanks!


Let's assume the valuie of the [Event_ID] control on the form is 123
(as Text Datatype).

Dim strRecID as String
strRecID = "[Event_ID]='" & Me![Event_ID] & "'"

will evaluate, using your syntax as
strRecID = "[Event_ID]= '123'"

Notice that the 123 above is within single quotes.
That is considered a Text value. When Access tries to match values in
the table, it's looking for '123' as text in a Number datatype field.
You'll get an #Error.

I gave you the correct syntax if [Event_ID] is a Number datatype.

Dim strRecID as String
strRecID = "[Event_ID]=" & Me![Event_ID]

The value of the [Event_ID] control on the form must be concatenated
into the string without the Single Quotes which delimits text.

So, if the value of [Event_ID] on the form is 123 (a Number Datatype)
strRecID = "[Event_ID] = " & [Event_ID]
will evaluate in the string variable as
strRecID = "[Event_ID] = 123"

strRecID is correctly a string but the value is 123 (a number).
Acess willl now search the [Event_ID] (Number datatype) field in the
table looking for the Number 123 and all is well.
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mysterious "Data type mismatch in criteria expression" error =?Utf-8?B?TWljaGFlbCBTdXR0a3VzLCBJSQ==?= Microsoft Access Queries 8 10th Nov 2005 05:57 PM
Mysterious "Data type mismatch in criteria expression" error =?Utf-8?B?TWljaGFlbCBTdXR0a3VzLCBJSQ==?= Microsoft Access VBA Modules 8 10th Nov 2005 05:57 PM
I have a data type mismatch if I select "H", but "A" selects. =?Utf-8?B?SG93YXJkIGluIEhhbW1vbmRzcG9ydA==?= Microsoft Access 4 6th Nov 2005 05:05 PM
"data type mismatch" trying to execute dialogue form Kevin Beck via AccessMonster.com Microsoft Access Reports 2 17th Jun 2005 03:53 AM
In query, getting "Data type mismatch in criteria expression" mess =?Utf-8?B?anNjY29ycHM=?= Microsoft Access Queries 2 14th Dec 2004 11:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:29 AM.