473,378 Members | 1,375 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,378 software developers and data experts.

Require to export to excel with the dynamic SQL generated during runtime in the Form

Hi,

I am creating the following query during run-time.

Dim ctl As Control
Dim varItem As Variant
Dim strSQL As String

Dim stDocName As String

'From the list box the table fields will be selected and a sql is generated

Set ctl = Me!lstFieldSelect
strSQL = "Select "
For Each varItem In ctl.ItemsSelected
strSQL = strSQL & ctl.ItemData(varItem) & ", "
Next varItem

strSQL = Left$(strSQL, Len(strSQL) - 2)
strSQL = strSQL & " from tblDocList"

Based on this SQL thats generated I need to create a empty excel file with the
field names as the heading of each columns in the excel.

Is there a code to create a Query with the sql created above during runtime.
So I can attach to the following for exporting to excel.

DoCmd.OutputTo acOutputQuery, (this has to be the dynamic query, above generated in the strSQL variable), acFormatXLS

Pls assist.
Thanks..

Regards,
Ruth.
Sep 21 '06 #1
2 2235
PEB
1,418 Expert 1GB
Hi,

Save your SQL as Query!

Set mydb = CurrentDb()
Set Myquery = mydb.CreateQueryDef(names, SQLS)


:)
Sep 21 '06 #2
Hi,

Save your SQL as Query!

Set mydb = CurrentDb()
Set Myquery = mydb.CreateQueryDef(names, SQLS)


:)
Hi,

Thank You for the help and the quick response, just what I was searching for..
I am new to Access Form. Thanks again.

Regards,
Ruth.
Sep 22 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Jean | last post by:
Hello, I have a form that performs a search, according to criteria that a user enters into the text boxes. When the user clicks on „Search", a SQL string (say strSQL) is built up with the...
2
by: Regnab | last post by:
I've got my code working so that it'll count the number of columns in the table and move across (eg Range A-P and then range Q-W). Problem is when I get to the end of the single letters and get...
11
by: Not Me | last post by:
Hi, I'm trying to export from a gridview control, to an excel file using code intended for a datagrid control (it's all over the web, can post if requested) I get the error. Control...
4
by: Frank | last post by:
Hello All, I ham using VS.NET 2003. Have followed instructions from http://gridviewguy.com/ArticleDetails.aspx?articleID=26 along with several other articles to no avail. I am pulling my hair...
7
by: Vanessa | last post by:
hi Everyone, I have two questions on exporting data to Excel using ASP (w/o converting formatted excel file into web page and then plug in the dynamic data): 1. Can we export data into...
0
by: Anish G | last post by:
Hi All, I am getting the below given error while running my application in live server. In my local machine, its working fine. Please help me as it is very urgent for me. Exception from...
2
by: VitorCastro | last post by:
Hello... First, sorry for my bad english... i have generated many pivot tables in Access 2003. and i want the code to export all of them to one single excel sheet and specific cell. i have...
3
by: aaronward | last post by:
i have a couple of books coming on programming access - but they have not arrived as of yet. i am a fluent excel vba programmer, but i am extending out into access. I am starting with a simple export...
3
by: =?Utf-8?B?TmV3YnJv?= | last post by:
Here's the long story short. At work we have to real-time generate a report(excel format) which involves a number of table joining. So to export into excel contentType 'application/vnd.ms-excel'...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.