Solved

Displaying QueryDef parameters entered by user

Posted on 2006-11-02
4
262 Views
Last Modified: 2008-02-01
I have a query that I export to a text file. The query has two parameters that ask the user to input a start date and an end date range. I would like to concatenate those two dates into the name of the exported file. The query is called from several forms in my application, so I can't just change the query to read these date parameters off of one form; everybody's happy with being prompted for the dates.

My code basically looks like this, which should give you the logic of what I'm trying to do:
************************************
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim rst As DAO.Recordset
Dim strFileLocation

Set db = CurrentDb
Set qdf = db.QueryDefs("MyQuery")

'(this is the part I can't figure out)
strFileLocation="C:\MyFileAsOf" & qdf.Parameters("[Start Date]") & "to" & qdf.Parameters("[End Date]")

DoCmd.TransferText acExportDelim, , "MyQuery", strFileLocation
*************************************

Basically, the issue is: how do I access the parameters that someone has passed to my query _after_ they've passed them?

Many thanks,
-Ed
0
Comment
Question by:eheraux
  • 2
4 Comments
 
LVL 39

Expert Comment

by:stevbe
ID: 17859895
qdf.Parameters("Start Date").Value
0
 
LVL 19

Expert Comment

by:Eric Sherman
ID: 17860042
stevbe & eheraux ...

Wouldn't you have to run the query first to populate the Start/End dates before you build the strFileLocation string???

You probably want to store the Start/End dates in variables from an Input Box then you can build the strFileLocation as well as modify the qdf to include the date parameters.

ET
0
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 17860739
FWIW I agree.

The querydef you create in code and the query called by name that you export are two different things.
You could use a function or two to provide the parameters (from global variables or table values).
Then they can be called at will - and the query can be exported again without prompt.
0
 
LVL 39

Accepted Solution

by:
stevbe earned 125 total points
ID: 17861640
and the long way around, without using temp tables ...

Public Function ExportQDF()

Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef
Dim prm As DAO.Parameter
Dim rst As DAO.Recordset
Dim fld As DAO.Field
Dim strPath As String
Dim intFile As Integer
Dim strData As String

Set dbs = CurrentDb
Set qdf = dbs.QueryDefs("qselQDFParams")

Set prm = qdf.Parameters("Start Date")
prm.Value = InputBox("Start Date")
strPath = "C:\MyFileAsOf_" & Format(prm.Value, "yyyymmdd")

Set prm = qdf.Parameters("End Date")
prm.Value = InputBox("End Date")
strPath = strPath & "_to_" & Format(prm.Value, "yyyymmdd") & ".txt"

Set rst = qdf.OpenRecordset

intFile = VBA.FreeFile
Open strPath For Append Access Write As #intFile
For Each fld In rst.Fields
    strData = strData & fld.Name & ""","""
Next
strData = Left$(strData, Len(strData) - 1)
Print #intFile, strData

Do While Not rst.EOF
    strData = vbNullString
    For Each fld In rst.Fields
        strData = strData & fld.Value & vbNullString & ""","""
    Next
    Print #intFile, strData
    rst.MoveNext
Loop

Close #intFile

'cleanup
Set fld = Nothing
rst.Close
Set rst = Nothing
Set prm = Nothing
Set qdf = Nothing
Set dbs = Nothing

End Function
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now