473,545 Members | 2,009 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VBA generated INSERT query works in access 2007 but not access 2003

1 New Member
I have an access 2007 database (on an XP machine) that extracts a large set of data from an Oracle db using ODBC. The data extraction is done with a dynamic passthru query that is then called in a make table query that inserts the data into a new table in another access database file. The remote mdb file is also created on the fly when code is run.

The passthru code is dynamic, with the SQL string being assigned to a variable that is then inserted into a passthru query using the querydef() function. VBA is also used to generate the make table query that then inserts the results of the passthru into a table in another mdb file. VBA is used to create this make table query because the location and name of the remote database is dynamic. The querydef function is used to place the INSERT code into a query, and the docmd.openquery function is used to run it. The DoCmd.TransferD atabase function is then used to link the remote table containing the data to the main mdb file that is executing the code.

This code has always worked on my XP machine using access 2007 and running on my local harddrive. However, when I tried running the code in the below scenarios I received the "Query input must contain at least one table or query" runtime error when the make table query is run.

1. I tried to run the code on another computer running access 2003 in Windows 7 with the main mdb file on a network drive. This creates the remote mdb file, but then generates the above error when the make table is run.

2. I then tried to run the code on a local HD in access 2003 on a Windows 7 machine. Again, the remote mdb file is created, but the make table query generates the above error.

3. Next I tried running it in access 2003 on an XP machine and still got the error. The remote mdb file is created, but the make table query still generates the above error.

4. I changed the make table query to insert the results of the passthru into a LOCAL table, not a table in a remote db, and the query ran successfully. I take this to mean that the SQL used in the passthru is ok.

Given that the error is generated on both Windows 7 and XP, whether on a network drive or local drive, it SEEMS that the issue is somehow related to access 2003. In all cases in which the runtime error was generated, the code did successfully create the remote mdb file. There just seems to be an issue with creating the new table in the remote mdb. I know there is an issue with using the Jet provider on Windows 64bit machines, but this code is also failing on XP machines running access 2003.

I have the below references checked in access 2007. When I view the references while running the code on the other computers in access 2003 the same references are checked, though the version numbers are lower.
Visual Basic for Applications
Microsoft Access 12.0 Object Library
OLE Automation
Microsoft DAO 3.6 Object Library
Microsoft ActiveX Data Object 2.1 Library
Microsoft Scripting Runtime

When I insert a debug.print to show the make table code that is generating the error I get:

SELECT DATA_PASS_THROU GH.*, * INTO DATA_TRANSACTIO NS IN '\\Folder1\Fold er2\Folder3\Tra nsactional Data\Product Set 1.mdb' FROM DATA_PASS_THROU GH;

The above looks fine, and runs fine in access 2007 on my XP machine. It just doesn't seem to run on any computer running access 2003. I can't figure out why.

Line 43 generates the "Query input must contain at least one table or query" error. Lines 36 - 43 are related to the query that is giving me trouble.

If anyone has any thoughts as to why I'm getting this error in access 2003 I'd love to hear them.

Expand|Select|Wrap|Line Numbers
  1. Public Sub CreateDatabaseInitial()
  2.  
  3. Dim dbConnectStr As String
  4. Dim Catalog As Object
  5. Dim cnt As ADODB.Connection
  6. Dim dbPath As String
  7. Dim SQL_CHBK As String
  8. Dim dbs As DAO.Database
  9. Dim conn As ADODB.Connection
  10. Dim rst As New ADODB.Recordset
  11. Dim SQLInsert As String
  12. Dim FSO As New FileSystemObject
  13. Dim ProdGroup As Integer    
  14. DoCmd.SetWarnings False
  15.  
  16. Set dbs = CurrentDb()
  17. Set conn = CurrentProject.Connection
  18.  
  19. If Not FSO.FolderExists(FolderCheck) Then MkDir Left(CurrentDb.Name, InStrRev(CurrentDb.Name, "\")) & "Transactional Data\"
  20.  
  21. 'Set database name and location here
  22. dbPath = Left(CurrentDb.Name, InStrRev(CurrentDb.Name, "\")) & "Transactional Data\" & "Product Set " & [ProdGroup] & ".mdb"
  23. dbConnectStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbPath & ";"
  24.  
  25. 'Create new database – this seems to run fine in access 2003
  26. Set Catalog = CreateObject("ADOX.Catalog")
  27. Catalog.Create dbConnectStr
  28. Set Catalog = Nothing
  29.  
  30. ‘The passthru SQL is very long, but works without issue, so I have not shown it       
  31. SQL_CHBK = "FUNCTIONING PASSTHRU SQL CONTAINED HERE"
  32.  
  33. ‘The below updates the passthru query with the SQL  
  34. dbs.QueryDefs("DATA_ PASS_THROUGH").SQL = SQL_CHBK
  35.  
  36. ‘The below query generates the runtime error when creating a table in a remote mdb
  37. ‘but it runs fine when I change it to place the data in a local table by removing the IN clause
  38. SQLInsert = "SELECT DATA_ PASS_THROUGH.*, * INTO DATA_TRANS IN '" & dbPath & "' FROM DATA_ PASS_THROUGH;"
  39.  
  40. dbs.QueryDefs("DATA_ INSERT").SQL = SQLInsert
  41.  
  42. ‘The below line generates the runtime error
  43. DoCmd.OpenQuery "DATA_ INSERT", acViewNormal, acReadOnly
  44.  
  45. ‘The below code doesn’t get executed in access 2003 because of the runtime error
  46. ‘but it works in access 2007
  47. DoCmd.TransferDatabase acLink, "Microsoft Access", dbPath, acTable, "DATA_TRANS", "DATA_TRANS_" & [ProdGroup]
  48.  
  49. DoCmd.SetWarnings True
  50.  
  51. End Sub
  52.  
  53.  
  54.  
Dec 8 '11 #1
1 2460
NeoPa
32,563 Recognized Expert Moderator MVP
Your SQL has :
Expand|Select|Wrap|Line Numbers
  1. SELECT [TableName].*
  2.      , *
  3. FROM   [TableName]
  4. etc
Can you see that only one of the *s should be there. If 2007 allowed you that SQL then it was clumsy to do so. That SQL is not correct.

PS. Congratulations on putting so much effort (and it was well organised too) into your question. I'm tired now, but I thought that much effort deserved some help. Good for you.
Dec 9 '11 #2

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

Similar topics

42
1637
by: aaron.kempf | last post by:
since Access 2007 is a 'major change' then i assume that MS is going to make a new newsgroup for it. I mean; when VB.net 2002 came out; they decided to rename the 'main vb newsgroup' as 'Microsoft.Public.Dotnet.Languages.VB' and now.. when people go to microsoft.public.vb they see 'vb as a dead language' so I nominate this newsgroup...
1
4014
by: Dave | last post by:
Hello All, I have Access 2007 on my home machine and use Access 2003 at work. Are there any options available to downgrade my home machine to 2003 (or run both versions) that don't involve paying full price for a new copy of 2003? I have tried to find the information on that on the Microsoft web sites, but have had no luck. I have the...
1
4294
by: hnpatel | last post by:
Hi to all, How to use insert query in php? I m using ODBC connection with access database.I want to save data in table. I m using database 'PHPDB1'. Table Name 'EDETAIL'. There r two fields in table: 'ENO' & 'ENAME'. I want to take to text box and one submit button. I want to save the value of text box in table when...
0
1212
by: Walter Konopacki | last post by:
Does anyone know if the problems displaying OLE objects in forms and reports has been addressed in Access 2007. Want to upgrade if it has been resolved. Any help greatly appeciated.
0
3146
by: WPW07 | last post by:
Hello Everyone, I stumbled onto something interesting and was wondering if anyone else has experienced it and how they fixed it. I've posted to several forums to no avail. I've got a datasheet subform developed in an Access 2003 database. Users can click on a row and delete the record on the datasheet. However, when we open the database...
0
1581
by: susan | last post by:
i am a bear of very little brain so please don't use too many abbreviations or technical jargon or it might melt alltogether... I have created a database with Access 2007 and saved it, via the 'microsoft button' thingy as a 2003 file so it would work on the computers at work except it doesn't. well the buttons don't work, and so consequently...
1
4027
by: kfry | last post by:
I am having an issue maybe someone can help with. I have written an application with Access 2003 on my XP pc. I then package it and install it on my VISTA Access 2007 PC. When I do this the wrong version of the application is run. Meaning, the form changes that I just made are not there, they are from the previous version. I know it is the...
1
1765
by: tbeers | last post by:
Good morning. I have an interesting chain of events. My 2007 program has been working fine on a network. I have a split database with tables on F:\timekeeper and front end on terminal server ""c:\programs\timekeeper." just like in the past. Have a small .cmd routine to insure that user has connection to F:\timekeeper. We have been...
2
1791
by: gabielmatos | last post by:
this is my query; string NPI = fields.GetValue(0).ToString(); string EntiType = fields.GetValue(1).ToString(); string ProvLastNameLegal = fields.GetValue(5).ToString(); string ProvFirsName = fields.GetValue(6).ToString(); string ProvMiddName = ...
1
1642
by: lisaflynn | last post by:
Just upgraded to Access 2007 from 2003....In the older version you could create a query relating to the table you had open just by opening a query while being in the table. I can't figure out a shortcut to do this in 2007. In 2007 I can be in a table, create a queries and I still have to go thru my list of tables to select the table the query is...
0
7475
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7409
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7921
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7437
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5982
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3465
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1900
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
720
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.