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

Use SQL to Import Data Directly Into Access

I have this code working. But I can only get the query to load the data into a listbox. Does anyone know how I can get it directly into a table(tblTest)? I have tried putting "Inset into tblTest *" at the beginning of the SQL string. It does not cause an error but it does not load the data into the table.

Thank you very much.

-------------------------------------------------------------------------------------------------------------------

Expand|Select|Wrap|Line Numbers
  1. Private Sub buttonLoad3_Click() 
  2. Dim dbs As DAO.Database 
  3. Dim qdf As DAO.QueryDef 
  4. Dim sSQL As String 
  5.  
  6. Set dbs = CurrentDb 
  7. Set qdf = dbs.CreateQueryDef("qryTest") 
  8.  
  9.  strSelect = "SELECT state_code, xxx, year, qtr " 
  10.              strFrom = "FROM production_db.dbo.sy_test sy_test " 
  11.              strWhere = "WHERE (state_code='88') AND" 
  12.              strWhere = strWhere & " (xxx='1234567890') AND " 
  13.              strWhere = strWhere & " (year=2007) AND " 
  14.              strWhere = strWhere & " (qtr=2)" 
  15.  
  16.             sSQL = strSelect & strFrom & strWhere 
  17.             qdf.SQL = sSQL 
  18.  
  19.          qdf.Connect = "ODBC;DSN=Sybase System 11;UID=YYYY;PWD=password;srvr=production;Database=production_db" 
  20.          Me.listTest.RowSource = "qryTest" 
  21.          Me.listTest.Requery                      
  22.  
  23.  DoCmd.DeleteObject acQuery, "qryTest" 
  24.  
  25. End Sub 
-------------------------------------------------------------------------------------------------------------------
Mar 6 '08 #1
4 2257
Rabbit
12,516 Expert Mod 8TB
Creating the query definition does not run the query. You can use a DoCmd.OpenQuery for that.
Mar 6 '08 #2
Scott Price
1,384 Expert 1GB
The DoCmd.RunSQL method is perhaps more appropriate when storing the SQL string in a variable.

Regards,
Scott
Mar 6 '08 #3
The DoCmd.RunSQL method is perhaps more appropriate when storing the SQL string in a variable.

Regards,
Scott
Scott,

I believe the problem with that method is that it can't see tblTest because it is in the target Access database but not in the source Sybase database. I can get it to work by running a make table query but I am trying to create as few querys as possible. I figured there was some way to make it work with createTableDef and recordsets. And my supervisor does not want me to link to ths Sybase tables. I am just trying to query the Sybase tables and dump the results into an Access table.
Mar 7 '08 #4
Scott Price
1,384 Expert 1GB
That does make a difference! Reading over your first post, I don't see anywhere that you mention exactly what you are trying to do! Please state the question as clearly as you can in the future.

The DAO method that you are using in your code isn't the best way to go with this kind of linking/importing. You'll need to use another method.

What prevents you from using Access' built-in import wizard?

Regards,
Scott
Mar 7 '08 #5

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

Similar topics

2
by: BUSHII | last post by:
I have big problem. In database MyDB.mdb I have table for example: ORDERS with colums: - Id int - Name varchar(20) Also I create same table in SQL Server 2k. I can manualy export this data...
13
by: usenet | last post by:
Hi. Can any of you explain the major differences in LOAD and IMPORT in laymen terms? I've read the DB2 docs: " Inserts data from an external file with a supported file format into a table,...
20
by: Steve Jorgensen | last post by:
Hi all, I've just finished almost all of what has turned out to be a real bear of a project. It has to import data from a monthly spreadsheet export from another program, and convert that into...
1
by: KS | last post by:
Hi, I have creatd a custom Outlook form with a few custom form fields. When completed the form is sent to me and goes into my Inbox. This works fine. Now Iam trying to write some code in...
3
by: Schultz | last post by:
I would like to know if it is possible to import data from MS Excel 2000 to a dataset using asp.net. The excel file would need to be uploaded to the server from a web page first, before the loaded...
1
by: ghadley_00 | last post by:
Hi, I have a MS access database table for which I regularly need to import fixed width text data. At present I have to to cut and paste the text data from its source to a text file, save the...
10
by: Niklas | last post by:
Hi Before I start coding I need to be sure that nobody else has not done it yet and that I can use it. I need an import utility which import data from Excel to a database or some object in...
3
by: Roy | last post by:
Hi All, I have an A2003 application .Recently we had a request to import data from IDL files and create some reports. Since I have no idea to do that using Access,I used Excel to import data and...
4
by: KMEscherich | last post by:
Version of Access = 2003 Hi there, is there a way to capture data using TERADATA SQL Assistant and import a portion of this database table into a Microsoft Access database table??? I currently...
4
by: Alvin SIU | last post by:
Hi all, I have 6 tables inside a MS Access 2003 mdb file. I want to convert them as DB2 version -8 tables in AIX 5.2. I have exported them as 6 XML files. The XML files look fine. Each...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.