Open Query from command form parameters

G

Guest

Hello-

I am having a problem with DoCmd.OpenQuery syntax. Can you help me with
proper syntax. I want to open a query that is specified in a form list box
(users select the query they want and click submit).

[Report Generator] = Form name
[reportFileName] = name of query

Here is the code I have been working with:

Private Sub Command60_Click()
DoCmd.OpenQuery [Forms]![Report Generator]![reportFileName]
End Sub


Also, do you know how I can add in some logic so if the file name selected
in the list box is a query than open the query, otherwise open a report. I
was thinking something like this.

if field x = x
then OpenQuery [Forms]![Report Generator]![reportFileName]
else OpenReport [Forms]![Report Generator]![reportFileName]
 
G

Guest

Just to make sure

Is [reportFileName] the name of the list box on the form? (it should be)
===============================================
You can use
DoCmd.OpenQuery Me.reportFileName
===============================================
Does the list box has only one column?
If the query name is the second column in the list box, then use

DoCmd.OpenQuery Me.reportFileName.Column(1)

The column count start with 0
===============================================

Do you get any error? and what ?
 

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