Can't create querydef variable because "user defined type not defi

K

kfguardian

I need to create a name for my SQL query so I can export my query to excel.
However, VB isn't recognizing the type "querydef"- ie doesn't like "As
querydef." I have yet to find anywhere where this is "user defined"???
Please help!

My ultimate goal is to export the records from an ado recordset that are
pulled into a form with this query. I tried just to use export and office
links but without linking the form to the table, I just get duplicates of the
current record (ie if there are 4 records after query, excel shows 4 rows all
with the same data).

I don't care which way it gets done at this point- I would just like to be
done with this part... it was supposed to be quick and easy?!

Set cnThisConnect = CurrentProject.Connection
strSQL = "SELECT * FROM tblInputData " _
& "WHERE (InputDate >= CONVERT(DATETIME, '" & datQueryStart
& "', 102)) AND" _
& " (InputDate < CONVERT(DATETIME, '" & ShiftEnd &
"', 102))"

rstNewInputData.Open strSQL, cnThisConnect, adOpenKeyset,
adLockOptimistic, adCmdText
 
B

Brendan Reynolds

kfguardian said:
I need to create a name for my SQL query so I can export my query to excel.
However, VB isn't recognizing the type "querydef"- ie doesn't like "As
querydef." I have yet to find anywhere where this is "user defined"???
Please help!


<snip>

Most likely you don't have a reference (Tools, References in the VBA editor)
to the DAO object library, which is where QueryDef is defined.
 
K

kfguardian

Hi Brendan,

That was my problem. However now I am getting a new problem: it is saying
my currentdb is empty and won't set the querydef. I am using adp with ADO
connection. Here is my code for that part:

Dim mydb As DAO.Database
Dim qdf As DAO.QueryDef

Set cnThisConnect = CurrentProject.Connection
strSQL = "SELECT * FROM tblInputData " _
& "WHERE (InputDate >= CONVERT(DATETIME, '" & datQueryStart
& "', 102)) AND" _
& " (InputDate < CONVERT(DATETIME, '" & ShiftEnd &
"', 102))"

rstNewInputData.Open strSQL, cnThisConnect, adOpenKeyset,
adLockOptimistic, adCmdText

Set mydb = currentdb()
Set qdf = mydb.CreateQueryDef("ShiftReport", strSQL)


fyi- I posted a new message for this but since I already have your attention
maybe you could followup- Thanks in advance.
 

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