Trouble with Report Preview Button on sub form

R

Robert

Sirs,

I have a button to call a report preview for a worksheet report which
is named worksheet_report. It works fine on the main form. I need to
move this button to a sub form which is named menu-9.

Private Sub Command2_Click()


Dim stDocName As String
Dim strWhere As String
If Me.NewRecord Then
MsgBox "Select a record to print"
Else
stDocName = "worksheet_report"
strWhere = "[ID]=" & Me![ID]
DoCmd.OpenReport stDocName, acPreview, , strWhere
End If


End Sub

This code is for the worksheet report button on the main form. What do
I need to change to get it to work on the sub menu form?
 
D

Dirk Goldgar

Robert said:
Sirs,

I have a button to call a report preview for a worksheet report which
is named worksheet_report. It works fine on the main form. I need to
move this button to a sub form which is named menu-9.

Private Sub Command2_Click()


Dim stDocName As String
Dim strWhere As String
If Me.NewRecord Then
MsgBox "Select a record to print"
Else
stDocName = "worksheet_report"
strWhere = "[ID]=" & Me![ID]
DoCmd.OpenReport stDocName, acPreview, , strWhere
End If


End Sub

This code is for the worksheet report button on the main form. What do
I need to change to get it to work on the sub menu form?


It's not obvious that anything needs to change. What error message do you
get when you click the button? Does the subform have a field called "ID"?
 

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