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

Printing a report from a command button on a form

P: 25
Hello Everyone!

I am trying to use the following code in an on click event procedure from a command button on a custom form set as a dialog box. The dialog box is opened from another form. The dialog box contains a list box[List1] & two command buttons "Print & Cancel". The list box has three columns taken from a table and is bound to the third column [ID]
The following code in the print command button.

Expand|Select|Wrap|Line Numbers
  1. Dim WClause
  2.     WClause = "[ID] = '" &[List1] & " ' "
  3.     DoCmd.OpenReport "Print One Uncomplete Report", whereCondition:=WClause
The problem is that I get a type mismatch error when the code is executed.
If I bind the list box to one of the other columns and change my code to reflect that field name it works fine.
The [ID] column is a numeric field in my table and also the primary key. The other columns in[List0] and my table are text. Is this why I get the error with the [ID] column? Because it is numeric? How can I make this work with the numeric column?

Thanks in Advance!
Jan 4 '07 #1
Share this Question
Share on Google+
4 Replies


NeoPa
Expert Mod 15k+
P: 31,487
1. Line 2 - & " ' " should not have a space before the ' (If it's numeric the (')s shouldn't be there at all).
2. Line 3 - When calling a procedure, parameters may be passed positionally or by name. It is not possible to mix the two as you have tried to do here. The line should be :
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenReport ReportName:="Print One Uncomplete Report",WhereCondition:=WClause
HTH.
Jan 4 '07 #2

P: 25
Thank You!
I will give this I try as sson as I get to work this P.M.

I realize the spaces should not have been there I only added them because it was difficult to see what was there with out them. Guess I should have left it as it was. sorry.

I will make the adjustments you suggested, retry, and let you know.

Thanks Again!
Jan 4 '07 #3

P: 25
Thank you so much!

After making your changes, my code executed perfectly.

Thank you so much for taking the time to answer.
You guys are great!
Just a little info for you. I work for a manufacturing facility of a large worldwide corporation. I was asked to develop a few files in Access to reside on our network that will be shared among depts. This is not what I was hired for but I have a little education in Access. (Very little, but more than anyone else here).

Most of the users here only have limited p.c. skills, so everything I do must have a simple interface. Therefore I have to create lots of forms with command buttons and try to keep my files secure so people can't poke around and mess with my code or macros.
Anyway, Enough with boring you, I'm sure I will be back for more help
and Thanks again.
Jan 4 '07 #4

NeoPa
Expert Mod 15k+
P: 31,487
Not boring at all.
It's nice to know that we are helping real people with real lives and all.
Puts colour to the picture.
Jan 4 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.