Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to debug the DoCmd.OpenReport options

Status
Not open for further replies.

bobleonard

Programmer
Mar 28, 2002
32
US
I got the following code off a tek-tip post:
When I run it, all the fields come up '#Name?'
I assume the query is bad, But it is: ID = 1
for first record. Any suggestions?


Private Sub Command226_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 = " & Str([ID])

MsgBox (strWhere)
DoCmd.OpenReport "rpt_Sp", acViewPreview, , "ID = " & Str([ID])
End If

Thanks,
BLeonrd
 
I tried the Me.ID and got the same results in the preview.
All fields were: #Name?
Thanks, even though
 
Does the report work if you don't have any filter applied?
How about hard-coding
Code:
Private Sub Command226_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] = 1"
        MsgBox "strWhere: " & strWhere
        DoCmd.OpenReport "rpt_Sp", acViewPreview, , strWhere
    End If
What is the record source of rpt_Sp? Are all of the Control Sources from the report controls in the query?

Duane
Hook'D on Access
MS Access MVP
 
Hi,

I found the problem. I had set this report to run as the result of a Query. When I added the code to print a single record, I deleted the Query as a data source (my mistake). I went back and pointed the data source to the table and all is well. My Bad! Thanks. BL
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top