Help with: Docmd.OpenReport

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Ok - I have searched these newsgroup articles for the perfect way to print an Access report (only of the Current Record) from a Data Access Page using a Command Button

The most success that I have been able to achieve is getting all of the records in the database to print. Good, but I only want the report to consist of info from the Current Record shown on the DAP

There has got to be some VB script that I can use to achieve this goal. Here is the current script "behind" the button

Docmd.OpenReport "ReportName",,acPrevie

Has anyone solved this mystery?
 
Felicia said:
Ok - I have searched these newsgroup articles for the perfect way to print an Access report (only of the Current Record) from a Data Access Page using a Command Button.

The most success that I have been able to achieve is getting all of the records in the database to print. Good, but I only want the report to consist of info from the Current Record shown on the DAP.

There has got to be some VB script that I can use to achieve this goal. Here is the current script "behind" the button:

Docmd.OpenReport "ReportName",,acPreview

The common approach to this question is to use the
OpenReport's WhereCondition argument:

Docmd.OpenReport "ReportName", acPreview, , "key=" & txtkey
 
I have tried to use a "Where Condition" that uses the Primary Key as criteria, and the DAP just froze up. Upon forcing the DAP to close, there appeared a small dialog box that asked for the Primary Key number of the record that I wanted to print and - It PRINTS! I'd rather print before closing IE...... ARRRRG! This is the script

DoCmd.OpenReport "ReportName",,acPreview,"ID = " & I

Next, I tried the following script and nothing happens when you click the print button

<SCRIPT language=vbscript event=onclick for=Command0
Dim OneRec As Strin
DoCmd.RunCommand acCmdSaveRecor
'Saves the record so it is available to print even if it was just create
OneRec="[ID]=" & Me.I
DoCmd.OpenReport "AssetDisposal",acViewPreview,,OneRe
</SCRIPT

This script also yields an expected end of statement at the "Dim OneRec As String" line

Should I expect different results because I am trying to do this procedure with a DAP instead of a regular form page
 
Felicia said:
I have tried to use a "Where Condition" that uses the Primary Key as criteria, and the DAP just froze up. Upon forcing the DAP to close, there appeared a small dialog box that asked for the Primary Key number of the record that I wanted to print and - It PRINTS! I'd rather print before closing IE...... ARRRRG! This is the script:

DoCmd.OpenReport "ReportName",,acPreview,"ID = " & ID

Next, I tried the following script and nothing happens when you click the print button:

<SCRIPT language=vbscript event=onclick for=Command0>
Dim OneRec As String
DoCmd.RunCommand acCmdSaveRecord
'Saves the record so it is available to print even if it was just created
OneRec="[ID]=" & Me.ID
DoCmd.OpenReport "AssetDisposal",acViewPreview,,OneRec
</SCRIPT>

This script also yields an expected end of statement at the "Dim OneRec As String" line.

Should I expect different results because I am trying to do this procedure with a DAP instead of a regular form page?


Maybe someone who has experience with DAP can explain it,
but other than having acPreview as a filter name I don't see
what could be causing the problems you're having. At least
fix the open report line:

DoCmd.OpenReport "ReportName", acViewPreview, ,"ID = " & ID

and see if the situation becomes any clearer.

If that doesn't make much difference, then I would suspect
some kind of corruption is the cause of such strange
behavior.
 
Back
Top