Re: Creating a query in code



If Access complains about an unknown data type on this line:
Dim db As DAO.Database
you need to set your references.

Choose References on the Tools menu (in the code window), and check the box
beside:
Microsoft DAO 3.6.

More info about references:
http://allenbrowne.com/ser-38.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

<paulquinlan100@xxxxxxxxxxx> wrote in message
news:1152201282.707831.199290@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Im still having problems...

For some reason the procedure doesnt even seem to run when i use
dbEngine

I've also tried using: Dim db As DAO.Database and the procedure wont
run, however if i rem out this line the procedure runs (but obviously
still doesnt do what i want it to!).

Ive tested it by putting a message box as the first line of the
procedure, and the box will not appear if either of the above
statements are included anywhere in the procedure.

Thanks again for any ideas
Paul

Allen Browne wrote:

How about creating a query for this task, and then assigning its SQL
property for export?

Example: say you create a query named qry4Export.
Then your code will do this:
Dim strSql As String
strSql = "SELECT ...
dbEngine(0)(0).qry4Export.SQL = strSql
DoCmd.OutputTo ...

<paulquinlan100@xxxxxxxxxxx> wrote in message
news:1152196425.993992.122140@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Im trying to programmatically create a query so that it can be exported
to excel using docmd.outputto. I can do this easily enough with a saved
query, but as the user has a variety of options so i dont want to have
to have to set up all the possible queries beforehand.

Should i be using QueryDef for this?? Ive tried and it appears as
though the code doesnt even run, it wont even let me break into the
procedure and any msgbox's put in dont appear.

Any ideas?
Thanks a lot for any help.
Paul


.



Relevant Pages

  • Re: Populat a NewRecord from Text boxes Revisited
    ... Tools | References, and check the entry for the DAO library... ... The Dim statement Dim db As DAO.Database, rs As DAO.Recordset, strSQL As ... Dim strSQL As String ...
    (comp.databases.ms-access)
  • Re: How do I test for no records returned in code?
    ... Dim rst As DAO.Recordset ... Dim strSQL as String ... References from the VB editor window, scroll down to find the Microsoft DAO ...
    (microsoft.public.access.queries)
  • Re: Code doesnt work on some computers
    ... suspect is a references problem. ... ' This section Creates the database. ... Dim wrkDefault As Workspace ... Set qdfPassthrough = CurrentDb.QueryDefs ...
    (microsoft.public.access.modulesdaovba)
  • Re: Export a reprot to Excel
    ... 'you can choose which worksheet will receive the data ... Dim objXLApp As Object 'Excel.Application ... Dim rst As DAO.Recordset ... 'replace with names and cell references that suit your template ...
    (microsoft.public.access.reports)
  • Re: Sending Word 2007 data to Excel 2007
    ... in the first row of the first sheet, you have inserted the names of the ... Microsoft Excel 12.0 Object Library ... Dim PathToUse As String ... are there any references on how to somehow "publish" the ...
    (microsoft.public.word.vba.general)