View Full Version : underlying form prints instead of report


usmcgrunt
09-16-2010, 06:06 PM
I have a database with a custom switchboard form with buttons that take the user to other forms. One of the underlying forms has a button that the user clicks to generate a report based on the forms current record.

I have set the two forms up as 'popup' as well as the report. I have coded the main form to close when the next form opens.

Now the code that I have on the form button to preview the report works perfectly. However, when the user attempts to print the report all that prints out is the main form, even if it is closed.

My first attempt was Allen Bunch's (aka RuralGuy) code from

http://allenbrowne.com/casu-15.html

**********************************
Private Sub btnPrintLC_Click()

Dim strReport As String
Dim strWhere As String

If Me.Dirty Then
Me.Dirty = False
End If

If Me.NewRecord Then
MsgBox "Select a record to print"
Else

strReport = "rptLC"
strWhere = "[LNumber] = """ & me!LNumber & """"

DoCmd.OpenReport strDocName, acPreview, , strWhere

End If
End Sub
************************************
this still resulted in the underlying form printing instead of the report.

Then, after some more research I tried some code I found at

http://thedailyreviewer.com/office/v...form-108129358 (http://thedailyreviewer.com/office/view/how-to-preview-report-from-pop-up-form-108129358)

************************************
Private Sub btnPrintLC_Click()

Me.Visible = False

Dim strReport As String
Dim strWhere As String

strReport = "rptLC"
strWhere = "[LNumber] = """ & me!LNumber & """"

Docmd.OpenReport strReport, acView Preview, , strWhere
While sysCmd(acSysCmdGetObjectState, acReport, "rptLC") = acObjStateOpen

DoEvents
Wend

Me.Visible = True
End Sub
***************************************
Again the same problem.

Further research leads me to believe that I am having some sort of FOCUS problem with my report. It prints right if I

1. Right click while my mouse is over the report and choose the print option.

2. Print directly from the report with no underlying forms open.

Unfortunately, neither of these options will work in the environment that I am developing this database for (i.e. users with zero knowledge of Microsoft Access). I know for a fact that they will default to the way they are used to printing documents and that is by the windows icon in the top left corner of the screen and then selecting print from there which will result in the report losing focus and the underling form printing.

Looking forward to some more suggestions to keep this fire going.

thanks, Sean

Trevor G
09-17-2010, 12:11 AM
Welcome to the Forum Sean,

Create a macro that will preview the report based on the record you are using on the form, in the action/arguments below you would use the form id field against the table id field to get a single record being previewed, this should over come your problem.

Then just drag the macro onto the form (Form needs to be in design view), it will create a command button for you.

I use this alot

Once it works for you then you can convert the macro into VBA on the form to get the error handling and have a back up as the MACRO

usmcgrunt
09-17-2010, 03:03 AM
Trevor, thanks for the welcome.

So, I gave what you said a try but I am still having the same problem. I even converted the macro to VBA and added a visible property of 'False' for the underlying form before running the print preview and then returned the value to 'True' afterwards but the report still loses focus and the record data prints in the form layout not the report layout.

The only way I can get the print out to print as intended is by right click of mouse while the cursor is over the report preview and then selecting print form the shortcut menu.

Any other ideas?

Thanks, Sean

Trevor G
09-17-2010, 03:41 AM
Ok then Sean,

Can you upload an extract of the database indicating which form and which report you are refering to.

There must be a work around as this is such a normal process.

By the way have you downloaded Microsofts sample databases for Forms/Reports/Queries to assist you with some dynamic options?

Here is a link to the reports sample and within it the options are there to download the forms and queries.

http://www.microsoft.com/downloads/en/details.aspx?FamilyId=71DB24A5%2DC76F%2D4EDA%2DBC9 A%2D5FAC336EF7F1&displaylang=en

usmcgrunt
09-17-2010, 03:50 AM
Trevor, thanks for the quick response,

I will work to get a sample of the database table, form, and report in question together to upload here. Might be a delay as my work network won't allow me to connect to foreign websites. I am in the U.S. Right now I am using my iPad 3G to send these messages.

In the meantime I will download the samples to referenced and see where that gets me.

To be continued..... Sean