Print Report using current data on Form

D

Don

I have a form (Main form & Subform) that I would like to print the current
records on the subform in a report. The following is the code I have but it
does not select only the [CDCNum] current on the form, it prints all records
regardless of the current record.

Private Sub Command107_Click()
On Error GoTo Err_Command107_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Tasks by Assigned To"
stLinkCriteria = "[CDCNum] =" & "'" & Me![Project Name] & "'"
DoCmd.OpenReport stDocName, acPreview, stLinkCriteria

Exit_Command107_Click:
Exit Sub

Err_Command107_Click:
MsgBox Err.Description
Resume Exit_Command107_Click

End Sub

Any ideas why this is not working?
 
D

Dirk Goldgar

Don said:
I have a form (Main form & Subform) that I would like to print the current
records on the subform in a report. The following is the code I have but
it
does not select only the [CDCNum] current on the form, it prints all
records
regardless of the current record.

Private Sub Command107_Click()
On Error GoTo Err_Command107_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Tasks by Assigned To"
stLinkCriteria = "[CDCNum] =" & "'" & Me![Project Name] & "'"
DoCmd.OpenReport stDocName, acPreview, stLinkCriteria

Exit_Command107_Click:
Exit Sub

Err_Command107_Click:
MsgBox Err.Description
Resume Exit_Command107_Click

End Sub

Any ideas why this is not working?


For one thing, you're missing a comma to represent the missing FilterName
argument in the call to OpenReport. Try this:

DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria

I have to assume that [Project Name] contains a text value that is
compatible with [CDCNum], even though the field names suggest otherwise.
 
D

Don

Dirk,

Yes [CDCNum] and [Project Name] the same data. Thank you for your help. It
works.
--
Thanks again,

Dennis


Dirk Goldgar said:
Don said:
I have a form (Main form & Subform) that I would like to print the current
records on the subform in a report. The following is the code I have but
it
does not select only the [CDCNum] current on the form, it prints all
records
regardless of the current record.

Private Sub Command107_Click()
On Error GoTo Err_Command107_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Tasks by Assigned To"
stLinkCriteria = "[CDCNum] =" & "'" & Me![Project Name] & "'"
DoCmd.OpenReport stDocName, acPreview, stLinkCriteria

Exit_Command107_Click:
Exit Sub

Err_Command107_Click:
MsgBox Err.Description
Resume Exit_Command107_Click

End Sub

Any ideas why this is not working?


For one thing, you're missing a comma to represent the missing FilterName
argument in the call to OpenReport. Try this:

DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria

I have to assume that [Project Name] contains a text value that is
compatible with [CDCNum], even though the field names suggest otherwise.


--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 

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

Similar Threads


Top