Report for Current Record

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
Do you have a control on your form named "Autonumber"? Do you have a field
in your table named "Autonumber"?
 
There is no control on the form named "Autonumber". There is a field in the
Table called Autonumber (PK).
Thanks for any further advice
 
Add a text box to your form:
Name: txtAutonumber
Control Source: Autonumber

Then change your code to:
stcriteria = "Autonumber = " & Me.txAutonumber
 
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
 
Does your report record source contain the field Autonumber?

The filter property is updated when you open the report with a "where
condition".
 
Yes Duane, The Report record source does contain the Field Autonumber.
Any other suggestions?
Thanks
 
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.
 
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
 
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
 
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
 
Back
Top