Report for Current Record

G

Guest

I have a control for printing details of an existing record only in a report
form with the following Onclick event procedure:
Private Sub Extract_Click()
On Error GoTo Err_Extract_Click

Dim stDocName As String
Dim strcriteria As String
stDocName = "Extract"
stcriteria = "Autonumber = " & Me.Autonumber
DoCmd.OpenReport stDocName, acPreview, , strciteria

Exit_Extract_Click:
Exit Sub

Err_Extract_Click:
MsgBox Err.Description
Resume Exit_Extract_Click

End Sub

When I click the control I get an error that is referring to Autonumber afer
the Me.

Could some please advise where I have gone wrong? Many thanks
 
D

Duane Hookom

Do you have a control on your form named "Autonumber"? Do you have a field
in your table named "Autonumber"?
 
G

Guest

There is no control on the form named "Autonumber". There is a field in the
Table called Autonumber (PK).
Thanks for any further advice
 
D

Duane Hookom

Add a text box to your form:
Name: txtAutonumber
Control Source: Autonumber

Then change your code to:
stcriteria = "Autonumber = " & Me.txAutonumber
 
G

Guest

Did that Duane, but same error. I have done this with another data base some
time ago and it worked, so cannot figure what the problem is, and in that
case I did not have the text box as mentioned. I notice that the report that
worked OK, the properties shows the following under "Filter" eg:
(Autonumber=2364), but the report I am trying to run on this data base has
the "Filter" line blank.
Any other suggestions would be appreciated & Thank you for your valuable time
 
D

Duane Hookom

Does your report record source contain the field Autonumber?

The filter property is updated when you open the report with a "where
condition".
 
G

Guest

Yes Duane, The Report record source does contain the Field Autonumber.
Any other suggestions?
Thanks
 
D

Duane Hookom

If your report contains a field named Autonumber in its Field List and your
form has a control named txtAutonumber and you use code like:
stcriteria = "[Autonumber] = " & Me.txAutonumber
You should not have an issue. If you do get a promprt for AutoNumber then
you may have a corruption issue. Try start over with your report.
 
G

Guest

Ok Will do. Thanks for all your help Duane.


Duane Hookom said:
If your report contains a field named Autonumber in its Field List and your
form has a control named txtAutonumber and you use code like:
stcriteria = "[Autonumber] = " & Me.txAutonumber
You should not have an issue. If you do get a promprt for AutoNumber then
you may have a corruption issue. Try start over with your report.

--
Duane Hookom
MS Access MVP

Roger Bell said:
Yes Duane, The Report record source does contain the Field Autonumber.
Any other suggestions?
Thanks
 
D

dogbite via AccessMonster.com

Roger said:
I have a control for printing details of an existing record only in a report
form with the following Onclick event procedure:
Private Sub Extract_Click()
On Error GoTo Err_Extract_Click

Dim stDocName As String
Dim strcriteria As String
stDocName = "Extract"
stcriteria = "Autonumber = " & Me.Autonumber
DoCmd.OpenReport stDocName, acPreview, , strciteria

Exit_Extract_Click:
Exit Sub

Err_Extract_Click:
MsgBox Err.Description
Resume Exit_Extract_Click

End Sub

When I click the control I get an error that is referring to Autonumber afer
the Me.

Could some please advise where I have gone wrong? Many thanks


I'm not sure how stuck on code you are but I'm had the same problem
work around

copy your table give it another name call it tbltwo

put a cmdbutton on the form

build a macro

open tbltwo
send file to it
print tbltwo
delete file
close tbltwo

you can put a cmdbutton that just puts current recordset in tbltwo
for printing several on the last recordset use the other cmd print them all
and delete them
 
D

dogbite via AccessMonster.com

dogbite said:
I have a control for printing details of an existing record only in a report
form with the following Onclick event procedure:
[quoted text clipped - 20 lines]
Could some please advise where I have gone wrong? Many thanks

I'm not sure how stuck on code you are but I'm had the same problem
work around

copy your table give it another name call it tbltwo

put a cmdbutton on the form

build a macro

open tbltwo
send file to it
print tbltwo
delete file
close tbltwo

you can put a cmdbutton that just puts current recordset in tbltwo
for printing several on the last recordset use the other cmd print them all
and delete them
I used a copy of my report and assined it to tbltwo
 

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

Top