473,394 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Creating a query in code

Hi

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

Jul 6 '06 #1
3 2689
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 ...
--
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.

<pa************@hotmail.comwrote in message
news:11**********************@b68g2000cwa.googlegr oups.com...
Hi

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

Jul 6 '06 #2
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 ...
--
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.

<pa************@hotmail.comwrote in message
news:11**********************@b68g2000cwa.googlegr oups.com...
Hi

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
Jul 6 '06 #3
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.

<pa************@hotmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
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 ...

<pa************@hotmail.comwrote in message
news:11**********************@b68g2000cwa.googleg roups.com...
>
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

Jul 6 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Indraneel Sheorey | last post by:
Hello, I want to set up a query in SQL Server that is "grouped by" a variable PRICE. Since PRICE takes on continuous decimal values, I want to create deciles based on this variable and then...
11
by: randi_clausen | last post by:
Using SQL against a DB2 table the 'with' key word is used to dynamically create a temporary table with an SQL statement that is retained for the duration of that SQL statement. What is the...
4
by: Jeremy Weiss | last post by:
Thanks to much help from everyone in my previous thread, I've made it a pretty fair ways into my billing/invoicing db. I'm now needing a way to cycle through all the records in a table and create...
7
by: Simon Bailey | last post by:
How do you created a query in VB? I have a button on a form that signifies a certain computer in a computer suite. On clicking on this button i would like to create a query searching for all...
1
by: longtim | last post by:
I have been having endless difficulty creating reports/queries that set any relevent parameters from controls in forms. I am creating an application under access 2003 but will target access...
6
by: ste | last post by:
Hi there, I'm just beginning to learn PHP and MySQL, but I'm finding it difficult! I wondered if someone could help me out with a problem I'm having, or at least point me in the right...
5
by: darnnews | last post by:
Hi, I have been creating a database to keep track of press clippings, but I have hit a couple stumbling blocks. Any help is much appreciate. 1) Seeing if my query is done I have the...
4
by: DeanL | last post by:
Hi Guys, I need some help creating a query that is going to take between 1 and 10 parameters. The parameters are entered on a form into text boxes that may have data or be empty. Is there a...
17
Motoma
by: Motoma | last post by:
This article is cross posted from my personal blog. You can find the original article, in all its splendor, at http://motomastyle.com/creating-a-mysql-data-abstraction-layer-in-php/. Introduction:...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.