By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,107 Members | 1,318 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,107 IT Pros & Developers. It's quick & easy.

Form Command Button Difficulty

P: n/a
Following is the code I am using, behind a command button, on a form to
print out only the report of that particular form.

******************** Code Start ************************
Dim strDocName As String
Dim strWhere As String
strDocName = "rptSomeReport"
strWhere = "[RunID]=" & me!RunID
DoCmd.OpenReport strDocName, acPreview, , strWhere
'******************** Code End ************************

The changes I have made to fit my record is as follows:

Dim strDocName As String
Dim strWhere As String
strDocName = "RptBinlabel"
strWhere = "[SlideLotNumber]=" & me!SlideLotNumber
DoCmd.OpenReport strDocName, acPreview, , strWhere

When I "click" the button on the form, I get the following error:

"Run time error '3464': Data type mismatch in the criteria expression"

When I run the debug, it highlights the bottom line of the code:

"DoCmd.OpenReport strDocName, acPreview, , strWhere"

I'm stuck... :) any help would be appreciated.

Bill.

Nov 12 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
What is the data type of SlideLotNumber in its table?
If it is a Text type field, you need extra quote marks:

strWhere = "[SlideLotNumber] = """ & me!SlideLotNumber & """"

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html

"William Bradley" <br******@magma.ca> wrote in message
news:Gc********************@magma.ca...
Following is the code I am using, behind a command button, on a form to
print out only the report of that particular form.

******************** Code Start ************************
Dim strDocName As String
Dim strWhere As String
strDocName = "rptSomeReport"
strWhere = "[RunID]=" & me!RunID
DoCmd.OpenReport strDocName, acPreview, , strWhere
'******************** Code End ************************

The changes I have made to fit my record is as follows:

Dim strDocName As String
Dim strWhere As String
strDocName = "RptBinlabel"
strWhere = "[SlideLotNumber]=" & me!SlideLotNumber
DoCmd.OpenReport strDocName, acPreview, , strWhere

When I "click" the button on the form, I get the following error:

"Run time error '3464': Data type mismatch in the criteria expression"

When I run the debug, it highlights the bottom line of the code:

"DoCmd.OpenReport strDocName, acPreview, , strWhere"

I'm stuck... :) any help would be appreciated.

Nov 12 '05 #2

P: n/a
"Allen Browne" <ab***************@bigpond.net.au> wrote in message
news:Kx********************@news-server.bigpond.net.au...
What is the data type of SlideLotNumber in its table?
If it is a Text type field, you need extra quote marks:

strWhere = "[SlideLotNumber] = """ & me!SlideLotNumber & """"


Thank you for this Allen, and yes, it is a text box, but when I made the
change, nothing happens. It does not print or give me an error message.

Bill.
Following is the code I am using, behind a command button, on a form to
print out only the report of that particular form.

******************** Code Start ************************
Dim strDocName As String
Dim strWhere As String
strDocName = "rptSomeReport"
strWhere = "[RunID]=" & me!RunID
DoCmd.OpenReport strDocName, acPreview, , strWhere
'******************** Code End ************************

The changes I have made to fit my record is as follows:

Dim strDocName As String
Dim strWhere As String
strDocName = "RptBinlabel"
strWhere = "[SlideLotNumber]=" & me!SlideLotNumber
DoCmd.OpenReport strDocName, acPreview, , strWhere

When I "click" the button on the form, I get the following error:

"Run time error '3464': Data type mismatch in the criteria expression"

When I run the debug, it highlights the bottom line of the code:

"DoCmd.OpenReport strDocName, acPreview, , strWhere"

I'm stuck... :) any help would be appreciated.


Nov 12 '05 #3

P: n/a
William,
Allen didn't ask if the [SlideLotNumber] was a text box.
He asked if the [SlideLotNumber] Datatype was text.
Open your table in Design View.
Find the SlideLotNumber field and see what it's Datatype is.
It will say either AutoNumber or Number (which are Number DataTypes),
or Text (which is Text DataType) or Memo.

If it is Number, your original Where clause should work.
If it is text, you can use Allen's strWhere clause
or
strWhere = "[SlideLotNumber]= '" & me!SlideLotNumber & "'"

The above all assume that there is a control on your form
named "SlideLotNumber" and a field in the table named
[SlideLotNumber].
--
Fred

Please reply only to this newsgroup.
I do not reply to personal e-mail.
"William Bradley" <br******@magma.ca> wrote in message
news:Nv********************@magma.ca...
"Allen Browne" <ab***************@bigpond.net.au> wrote in message
news:Kx********************@news-server.bigpond.net.au...
What is the data type of SlideLotNumber in its table?
If it is a Text type field, you need extra quote marks:

strWhere = "[SlideLotNumber] = """ & me!SlideLotNumber & """"


Thank you for this Allen, and yes, it is a text box, but when I made the
change, nothing happens. It does not print or give me an error message.

Bill.
Following is the code I am using, behind a command button, on a form to print out only the report of that particular form.

******************** Code Start ************************
Dim strDocName As String
Dim strWhere As String
strDocName = "rptSomeReport"
strWhere = "[RunID]=" & me!RunID
DoCmd.OpenReport strDocName, acPreview, , strWhere
'******************** Code End ************************

The changes I have made to fit my record is as follows:

Dim strDocName As String
Dim strWhere As String
strDocName = "RptBinlabel"
strWhere = "[SlideLotNumber]=" & me!SlideLotNumber
DoCmd.OpenReport strDocName, acPreview, , strWhere

When I "click" the button on the form, I get the following error:

"Run time error '3464': Data type mismatch in the criteria expression"

When I run the debug, it highlights the bottom line of the code:

"DoCmd.OpenReport strDocName, acPreview, , strWhere"

I'm stuck... :) any help would be appreciated.



Nov 12 '05 #4

P: n/a
At the top of your code, add this line:
Stop

When you click the button, Access should stop at this line.
Now press F8, so it moves to the next line.
Continue to press F8, one line at a time, and observe what is happening.
Does the OpenReport line exectute?

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html

"William Bradley" <br******@magma.ca> wrote in message
news:Nv********************@magma.ca...
"Allen Browne" <ab***************@bigpond.net.au> wrote in message
news:Kx********************@news-server.bigpond.net.au...
What is the data type of SlideLotNumber in its table?
If it is a Text type field, you need extra quote marks:

strWhere = "[SlideLotNumber] = """ & me!SlideLotNumber & """"


Thank you for this Allen, and yes, it is a text box, but when I made the
change, nothing happens. It does not print or give me an error message.

Bill.
Following is the code I am using, behind a command button, on a form to print out only the report of that particular form.

******************** Code Start ************************
Dim strDocName As String
Dim strWhere As String
strDocName = "rptSomeReport"
strWhere = "[RunID]=" & me!RunID
DoCmd.OpenReport strDocName, acPreview, , strWhere
'******************** Code End ************************

The changes I have made to fit my record is as follows:

Dim strDocName As String
Dim strWhere As String
strDocName = "RptBinlabel"
strWhere = "[SlideLotNumber]=" & me!SlideLotNumber
DoCmd.OpenReport strDocName, acPreview, , strWhere

When I "click" the button on the form, I get the following error:

"Run time error '3464': Data type mismatch in the criteria expression"

When I run the debug, it highlights the bottom line of the code:

"DoCmd.OpenReport strDocName, acPreview, , strWhere"

I'm stuck... :) any help would be appreciated.

Nov 12 '05 #5

P: n/a

"Fredg" <fg******@att.net> wrote in message
news:19***********************@bgtnsc05-news.ops.worldnet.att.net...
William,
Allen didn't ask if the [SlideLotNumber] was a text box.
He asked if the [SlideLotNumber] Datatype was text.
Open your table in Design View.
Find the SlideLotNumber field and see what it's Datatype is.
It will say either AutoNumber or Number (which are Number DataTypes),
or Text (which is Text DataType) or Memo.

If it is Number, your original Where clause should work.
If it is text, you can use Allen's strWhere clause
or
strWhere = "[SlideLotNumber]= '" & me!SlideLotNumber & "'"

The above all assume that there is a control on your form
named "SlideLotNumber" and a field in the table named
[SlideLotNumber].


Thank you Fredg, the datatype is text. Your code above does bring the
appropriate report to the screen but does not print it. Which is what I am
trying to achieve. When the operator fills out the form, I want them to be
able to hit "Print Report" and the appropriate form will then print out and
that report only. As you know to simply hit "print" in reports, gets you all
of them unless you select a particular record.

Bill.
Nov 12 '05 #6

P: n/a

"Allen Browne" <ab***************@bigpond.net.au> wrote in message
news:o9********************@news-server.bigpond.net.au...
At the top of your code, add this line:
Stop

When you click the button, Access should stop at this line.
Now press F8, so it moves to the next line.
Continue to press F8, one line at a time, and observe what is happening.
Does the OpenReport line exectute?


Thank you Allen and yes it does step through all the lines. It brings the
appropriate report to the screen but does not print it out. Maybe something
is missing in the code. I got this code from:
http://www.mvps.org/access/reports/rpt0002.htm

Bill.
Nov 12 '05 #7

P: n/a
"Jamie" <ji*************@hotmail.com> wrote in message
news:bk**********@news7.svr.pol.co.uk...
Your problem is with the DoCmd line:
DoCmd.OpenReport strDocName, acPreview, , strWhere

You are using acPreview which is supposed to preview the report on the
screen, you should instead use acViewNormal:
DoCmd.OpenReport strDocName, acViewNormal, , strWhere

This command will print your report.


Thank you for this Jamie, I will give it a try.

Bill.
Nov 12 '05 #8

P: 23
Im trying similar I need to print only the report page that coisides with the form I am filling in at that time.

both report and form are in Justified

they are for searchs ie we collate data per search on one form and have to print out one report page = one a4 paper size per report

ive tried using certain codes building it into the form command button I have designated in the expression build area ((right clicking on button))

I am new to this sort of thing but really want to learn it Pleae can some one explain in english for me ive used the codes above but seem to be doing some thing wrong because im getting nothing or all report pages and I have a data base of over a thousand :confused: :eek: :mad:
Jul 14 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.