dlookup in report output

N

nevpoe

I am trying to use a lookup in my output function. However, I keep getting
"You stopped your previous command" Error. What is wrong with this?

Dim stDocName As String

stDocName = "tblAF report"
stOutputName = "P:\Gardner\common\Lab\asfired\" &
Format(DLookup("[analysis date]", "tblAF2 Query"), "mmddyyyy") & ".snp"
DoCmd.OutputTo acReport, stDocName, "Snapshot Format", stOutputName,
True, "", 0

Exit_AFSAVE_Click:
Exit Sub

Err_AFSAVE_Click:
MsgBox Err.Description
Resume Exit_AFSAVE_Click

End Sub
 
J

John Spencer

Try surrounding the query name in the DLookup with []

I would probably Dim another variable and assign the results of the dLookup to
the variable, just to make sure of what I was getting.

stOutputName = "P:\Gardner\common\Lab\asfired\" &
Format(DLookup("[analysis date]", "[tblAF2 Query]"), "mmddyyyy") & ".snp"

Dim vTheDate as Variant
vDate = DLookup("[analysis date]", "[tblAF2 Query]")
If IsNull(VDate) then
Msgbox "Your message here"
Exit Sub
End iF
 
N

nevpoe

Thanks. I tried it, but to get the lookup to work I had to write a input box
in so that people could just input the file name to save as. I have another
problem now. Everything works correctly, but the report is from a parameter
query. So basically, I now have 2 dialog boxes asking for the same
information. Is there any way I can link the input box to fill in the
criteria for the query behind the report.

John Spencer said:
Try surrounding the query name in the DLookup with []

I would probably Dim another variable and assign the results of the dLookup to
the variable, just to make sure of what I was getting.

stOutputName = "P:\Gardner\common\Lab\asfired\" &
Format(DLookup("[analysis date]", "[tblAF2 Query]"), "mmddyyyy") & ".snp"

Dim vTheDate as Variant
vDate = DLookup("[analysis date]", "[tblAF2 Query]")
If IsNull(VDate) then
Msgbox "Your message here"
Exit Sub
End iF


I am trying to use a lookup in my output function. However, I keep getting
"You stopped your previous command" Error. What is wrong with this?

Dim stDocName As String

stDocName = "tblAF report"
stOutputName = "P:\Gardner\common\Lab\asfired\" &
Format(DLookup("[analysis date]", "tblAF2 Query"), "mmddyyyy") & ".snp"
DoCmd.OutputTo acReport, stDocName, "Snapshot Format", stOutputName,
True, "", 0

Exit_AFSAVE_Click:
Exit Sub

Err_AFSAVE_Click:
MsgBox Err.Description
Resume Exit_AFSAVE_Click

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