Print Report using current data on Form

  • Thread starter Thread starter Don
  • Start date Start date
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?
 
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,

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)
 
Back
Top