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
************************************
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