data type error 3464 - print record

C

clayton ledford

I have a form that i added the following code to a button. It allowed me to
print a Report, but only for the one record showing in the form on the click
event:

DoCmd.OpenReport "YourReport", acPreview
Reports![YourReport].Filter = "YourPrimaryKey = " & Me![YourPrimaryKeyControl]
Reports![YourReport].FilterOn = True

It was working perfectly, but a query that i'm running now required me to
change my primary key in my table to Text instead of Number. My form still
updates information properly, but the print button gives me the data type
missmatch error 3464.

Which portion needs updated? Form, report, code? Other?
 
A

Allen Browne

You need extra quote marks in the WhereCondition string if it is a text
field:

Dim strWhere As String
strWhere = "YourPrimaryKey = """ & Me![YourPrimaryKeyControl] & """
DoCmd.OpenReport "YourReport", acPreview, , strWhere

If the quotes don't make sense, see:
Quotation marks within quotes
at:
http://allenbrowne.com/casu-17.html

Note that using the WhereCondition of OpenReport will be more efficient than
opening the entire thing, and then applying a filter.

Also, I've suggested using a string, to make it easier to debug, e.g.:
Debug.Print strWhere

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

message
news:D[email protected]...
 
C

clayton ledford

I used your updated code, and it worked perfectly. I tried to modify what i
had already, but i think i need to read your article on quotes first.

Thank you very much for solving this problem for me.

Allen Browne said:
You need extra quote marks in the WhereCondition string if it is a text
field:

Dim strWhere As String
strWhere = "YourPrimaryKey = """ & Me![YourPrimaryKeyControl] & """
DoCmd.OpenReport "YourReport", acPreview, , strWhere

If the quotes don't make sense, see:
Quotation marks within quotes
at:
http://allenbrowne.com/casu-17.html

Note that using the WhereCondition of OpenReport will be more efficient than
opening the entire thing, and then applying a filter.

Also, I've suggested using a string, to make it easier to debug, e.g.:
Debug.Print strWhere

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

message
I have a form that i added the following code to a button. It allowed me
to
print a Report, but only for the one record showing in the form on the
click
event:

DoCmd.OpenReport "YourReport", acPreview
Reports![YourReport].Filter = "YourPrimaryKey = " &
Me![YourPrimaryKeyControl]
Reports![YourReport].FilterOn = True

It was working perfectly, but a query that i'm running now required me to
change my primary key in my table to Text instead of Number. My form
still
updates information properly, but the print button gives me the data type
missmatch error 3464.

Which portion needs updated? Form, report, code? Other?
 

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


Top