Printing Report

G

Guest

Here is the code for my command button, i was trying to print the data on the
current record of the form i am in, but it went to print preview, all the
field is blank..no data showing, only show the field names..please help.
Private Sub cmdPrint_Click()
Dim strwhere As String
If Me.Dirty Then 'save any edits.
Me.Dirty = False
End If
If Me.NewRecord Then 'check there is a record to point
MsgBox "select a record to print"
Else
strwhere = [Mailing ListID] = "&me.[Mailing ListID]"
DoCmd.OpenReport "Mailing List", acViewPreview, , strwhere
End If
End Sub
 
G

Guest

Try opening the Report using acViewPreview
then use the filter to limit the displayed record as in
report.filteron = False
report.filter = "[Mailing ListID] = " & me.[Mailing ListID]
report.filteron = True
 
D

Duane Hookom

You had the quotes around the wrong expression. The following assumes the
Mailing ListID field is numeric.

Private Sub cmdPrint_Click()
Dim strwhere As String
If Me.Dirty Then 'save any edits.
Me.Dirty = False
End If
If Me.NewRecord Then 'check there is a record to point
MsgBox "select a record to print"
Else
strwhere = "[Mailing ListID] = " & Me.[Mailing ListID]
DoCmd.OpenReport "Mailing List", acViewPreview, , strwhere
End If
End Sub
 
G

Guest

Thank you for your help, i got it working good.

Duane Hookom said:
You had the quotes around the wrong expression. The following assumes the
Mailing ListID field is numeric.

Private Sub cmdPrint_Click()
Dim strwhere As String
If Me.Dirty Then 'save any edits.
Me.Dirty = False
End If
If Me.NewRecord Then 'check there is a record to point
MsgBox "select a record to print"
Else
strwhere = "[Mailing ListID] = " & Me.[Mailing ListID]
DoCmd.OpenReport "Mailing List", acViewPreview, , strwhere
End If
End Sub


--
Duane Hookom
MS Access MVP


Carol Shu said:
Here is the code for my command button, i was trying to print the data on
the
current record of the form i am in, but it went to print preview, all the
field is blank..no data showing, only show the field names..please help.
Private Sub cmdPrint_Click()
Dim strwhere As String
If Me.Dirty Then 'save any edits.
Me.Dirty = False
End If
If Me.NewRecord Then 'check there is a record to point
MsgBox "select a record to print"
Else
strwhere = [Mailing ListID] = "&me.[Mailing ListID]"
DoCmd.OpenReport "Mailing List", acViewPreview, , strwhere
End If
End Sub
 

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