When printing Report, fields are blank (1 Viewer)

taenite

Registered User.
Local time
Today, 06:54
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.
 

taenite

Registered User.
Local time
Today, 06:54
Joined
Jun 26, 2001
Messages
13
Record source for both the form and the report is table titled "CAR"
 

boblarson

Smeghead
Local time
Yesterday, 22:54
Joined
Jan 12, 2001
Messages
32,059
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.
 

taenite

Registered User.
Local time
Today, 06:54
Joined
Jun 26, 2001
Messages
13
Im confused.

I dont have a table field titled "CAR"

"CAR" is only the name of my table.
 

boblarson

Smeghead
Local time
Yesterday, 22:54
Joined
Jan 12, 2001
Messages
32,059
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.
 

taenite

Registered User.
Local time
Today, 06:54
Joined
Jun 26, 2001
Messages
13
I once did have CARNumber as CAR...Now Im glad I changed it : )

No idea otherwise what might be making the report blank though?
 

boblarson

Smeghead
Local time
Yesterday, 22:54
Joined
Jan 12, 2001
Messages
32,059
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.
 

taenite

Registered User.
Local time
Today, 06:54
Joined
Jun 26, 2001
Messages
13
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

  • copy of car.zip
    98.8 KB · Views: 96

boblarson

Smeghead
Local time
Yesterday, 22:54
Joined
Jan 12, 2001
Messages
32,059
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.
 

Autoeng

Why me?
Local time
Today, 01:54
Joined
Aug 13, 2002
Messages
1,302
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
 

taenite

Registered User.
Local time
Today, 06:54
Joined
Jun 26, 2001
Messages
13
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.
 

taenite

Registered User.
Local time
Today, 06:54
Joined
Jun 26, 2001
Messages
13
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.
 

Autoeng

Why me?
Local time
Today, 01:54
Joined
Aug 13, 2002
Messages
1,302
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.
 

boblarson

Smeghead
Local time
Yesterday, 22:54
Joined
Jan 12, 2001
Messages
32,059
Here's your database, with my changes. Look through to see what I did.
 

Attachments

  • db5.zip
    40 KB · Views: 97

taenite

Registered User.
Local time
Today, 06:54
Joined
Jun 26, 2001
Messages
13
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 : )
 

taenite

Registered User.
Local time
Today, 06:54
Joined
Jun 26, 2001
Messages
13
Bob and Aero.

Thanks for all your hard work and patience with me.

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

ets960

Registered User.
Local time
Today, 00:54
Joined
Jun 2, 2005
Messages
21
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

Top Bottom