Print Current Record to Report (1 Viewer)

Ukraine82

Registered User.
Local time
Yesterday, 22:03
Joined
Jun 14, 2004
Messages
346
I'm having hard trouble doing print preview current record from form with subform to a report.

When using the code below I'm getting an error for:

The specified field [PolicyNum] could refer to more than 1 table listed in the from clause of your sql statement.

Dim strDocName As String
Dim strLinkCriteria As String

strDocName = "rptCurrentInfo"
strLinkCriteria = "[PolicyNum] = Forms![frmAdjusterMod]![PolicyNum]"

DoCmd.OpenReport strDocName, acViewPreview, , strLinkCriteria


Command button is in the main form frmadjustermod - sbfm is sbfmMoreMod

foreign key is PolicyNum

Thanks,
Michael
 

ghudson

Registered User.
Local time
Today, 01:03
Joined
Jun 8, 2002
Messages
6,195
I believe in the SQL of your report you need to define which table the PolicyNum is coming from. Like this...

TableA.PolicyNum

instead of just

PolicyNum
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 01:03
Joined
Feb 19, 2002
Messages
43,213
You need to save the current record before opening the report.

Code:
Dim strDocName As String
Dim strLinkCriteria As String

strDocName = "rptCurrentInfo"
strLinkCriteria = "[PolicyNum] = Forms![frmAdjusterMod]![PolicyNum]"

[COLOR=Red]DoCmd.RunCommand acCmdSaveRecord[/COLOR]

DoCmd.OpenReport strDocName, acViewPreview, , strLinkCriteria
 

Ukraine82

Registered User.
Local time
Yesterday, 22:03
Joined
Jun 14, 2004
Messages
346
ghudson said:
I believe in the SQL of your report you need to define which table the PolicyNum is coming from. Like this...

TableA.PolicyNum

instead of just

PolicyNum

ghudson,

Thanks I really appreciated

Michael
 

secy

New member
Local time
Yesterday, 22:03
Joined
Nov 30, 2019
Messages
3
This is really worked.


Syntax:
DoCmd.OpenReport "REPORT NAME", acViewPreview, , "[PRIMARY KEY] = " & Me.PRIMARY_KEY


Uses:
DoCmd.OpenReport "Purchase Order", acViewPreview, , "[Order Number]=" & Me.Order_Number
 

AccessBlaster

Registered User.
Local time
Yesterday, 22:03
Joined
May 22, 2010
Messages
5,913
http://allenbrowne.com/casu-15.html

Code:
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 print
        MsgBox "Select a record to print"
    Else
        strWhere = "[ID] = " & Me.[ID]
        DoCmd.OpenReport "MyReport", acViewPreview, , strWhere
    End If
End Sub
 

Gasman

Enthusiastic Amateur
Local time
Today, 06:03
Joined
Sep 21, 2011
Messages
14,221
Very, very old post ressurrected by a poster who also replied to two other old posts.?
 

Users who are viewing this thread

Top Bottom