open a report based on current record

G

Guest

Hello all, I really thought i would be able to achieve this without help, but
no.

i have a form "partnumbersearch" that searches through records and returns
matching records in the form. I have a button on the form that if clicked
opens another form at the currently displayed record. This is achieved by
using the following >
Private Sub Command10_Click()
On Error GoTo Err_Command10_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Tabbed Data Entry"

stLinkCriteria = "[activityID]=" & Me![activityID]
DoCmd.OpenForm stDocName, , , stLinkCriteria


DoCmd.Close acForm, "Part Number Search"



Exit_Command10_Click:
Exit Sub

Err_Command10_Click:
MsgBox Err.Description
Resume Exit_Command10_Click

End Sub

I want another button on the form that will open a report using the current
record details.
I foolishly imagined i could simple copy and paste the above and change to
the following>

Private Sub Command21_Click()
On Error GoTo Err_Command21_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "part number history"

stLinkCriteria = "[activityID]=" & Me![activityID]
DoCmd.Openreport stDocName, , , stLinkCriteria


DoCmd.Close acForm, "Part Number Search"



Exit_Command21_Click:
Exit Sub

Err_Command21_Click:
MsgBox Err.Description
Resume Exit_Command21_Click

End Sub

but no obviously i can not.

I simply change the command10 to command21 (new button)
changed the docname i want to open to "part number history"
and changed the openform to openreport.

help please
 
M

Marshall Barton

Maax wrote:
[snip code for form]
I want another button on the form that will open a report using the current
record details.
I foolishly imagined i could simple copy and paste the above and change to
the following>

Private Sub Command21_Click()
On Error GoTo Err_Command21_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "part number history"

stLinkCriteria = "[activityID]=" & Me![activityID]
DoCmd.Openreport stDocName, , , stLinkCriteria

DoCmd.Close acForm, "Part Number Search"
Exit_Command21_Click:
Exit Sub

Err_Command21_Click:
MsgBox Err.Description
Resume Exit_Command21_Click

End Sub


Except for closing the form, I use that exactlogic all the
time. What kind of problem are you having with it?
 

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