When printing Report, fields are blank

taenite

Registered User.
Local time
Today, 18:12
Joined
Jun 26, 2001
Messages
13
I have looked up many examples and concocted the following code which is under a command in a form.

I would like this command to print the current record in the form as a report.

However, when it prints, the report template is there..but the data is not.

What could I be doing incorrectly?

Private Sub PrintReport_Click()
On Error GoTo Err_PrintReport_Click

Dim stDocName As String
Dim strWhere As String

stDocName = "CAREPORTS"
strWhere = "[CARNumber]=" & Me![CARNumber]
DoCmd.OpenReport stDocName, , , strWhere

Exit_PrintReport_Click:
Exit Sub

Err_PrintReport_Click:
MsgBox Err.Description
Resume Exit_PrintReport_Click

End Sub

I have triple checked that both fields are named CARNumber, so that isnt the problem.

Thanks Everyone.
 
Record source for both the form and the report is table titled "CAR"
 
Well, first up, I'm not sure if this is part of your problem. But, it can cause some bad things to happen. You need to make sure that your control on your form is NOT named the same as your table field.

If you created your form with the Microsoft Wizard, it does a stupid thing and names the bound controls the same name as the table or query's field name. This can cause major problems as Access at times will be trying to figure out if you mean the control or the field and it will go wacky. I named that as my number one pet peeve when I filled out a survey that Microsoft sent me as part of the Pacific Northwest Access Users Group.

It can confuse the @#$$ out of people.
 
Im confused.

I dont have a table field titled "CAR"

"CAR" is only the name of my table.
 
Sorry for the confusion. I saw your WHERE clause:

"[CARNumber]=" & Me![CARNumber]

and thought I might make mention of the fact that if you had a control on the form that was also named CARNumber that it might cause a problem. One thing to note - That it does the same thing with reports as well. If a control on the report is named CARNumber then it could cause a problem.
 
I once did have CARNumber as CAR...Now Im glad I changed it : )

No idea otherwise what might be making the report blank though?
 
If you get rid of the WHERE clause, does it open okay with data?

If it doesn't, then we've been looking in the wrong place.

If it does, then if you can zip and upload your database (even a stripped down version with only the table, report, and form), then I can have a look and see if I can't figure it out.
 
It doesnt work. Hopefully you have access 97 - which is what I am using. I sent the file to a friend, and he says the code works in his access XP - but he cant explain to me why.

I dont have the ability to convert the file to XP, so i still have to find out what is wrong and fix it.

Ive attached the database. I basically deleted EVERYTHING since it was well over 460 kb to start.

Thanks so much : )

The print button is in the only form - "FormEditCAR"
 

Attachments

Just as I had said. You have a text box on the Report that is named CARNumber and the field name is CARNumber. Change the control to txtCARNumber and also on the form.

Now, after that is done, why not put in the report's on open event:

Reports!CAREPORTS.RecordSource = "SELECT CAR.* FROM CAR WHERE (((CAR.CARNumber)=[Forms]![FormEditCAR]![txtCARNumber]));"

And then take off the WHERE criteria of the open form part. That definitely works.

Also, I used the Docmd.OpenReport "CAREPORTS", acViewPreview so that I could preview before printing.
 
If you have any fields on your form that Allow Zero Length = No and that field has not been filled in when you print the report the entire report will be blank.

Also, try saving the record before printing like so...

stDocName = "CAREPORTS"
strWhere = "[CARNumber]=" & Me![CARNumber]
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport stDocName, , , strWhere
 
Ok: Bare with me.

1) Allow Zero Length = No.
..changed all my tables values to Yes.
--Didnt solve the problem

2) Just as I had said. You have a text box on the Report that is named CARNumber and the field name is CARNumber. Change the control to txtCARNumber and also on the form.

Changed Textbox name in form and report to txtcarnumber. Incorporated that into my code. When I click the print button now...i am prompted for a paramenter value for txtcarnumber. which doest make sense to me.

3)It says there is an error with the code you gave me. Im not to code saavy to understand what it is :-/

Hopefully if i can figure that out...i might be able to get it to work, but that still doesnt explain why it prompts me for txtcarnumber.

Thanks so much for all your help. sorry for all the trouble.
 
oh, i deleted the where clause, so that now it doesnt prompt me for txtcarnumber when I click print. But there is still that syntax error, so the report wont open.
 
Which code are you having an error with?

As for the parameter is the reports recordsource a query? If so you will have to change the CARNumber field there to txtCARNumber also.
 
Here's your database, with my changes. Look through to see what I did.
 

Attachments

its a table.

i attached the REALLY shortened/deleted version in one of the earlier posts if you wish to look at it.

thanks for your help : )
 
Bob and Aero.

Thanks for all your hard work and patience with me.

I have gotten it to work thanks to your help! : )
 
Thank You!!!

Bob-

I was having the same problem as the parent, and your code solved my problem also! Thank you very much!
 

Users who are viewing this thread

Back
Top Bottom