473,396 Members | 1,921 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.

Append query as string SQL statement

Hi I'm a new user with Access and I need help with some VBA syntax. I am trying to run an append query using a string SQL statement. Basically, I need to append to "tbl_All" various fields from two different tables.

I need this to be dynamic because depending on what the user selects, it needs to take fields from a specific table. I am therefore using a variable to refer to this table: EquipmentTbl is the variable that i have already defined.

This is my code:
Expand|Select|Wrap|Line Numbers
  1. Dim StrSQL As String
  2.  
  3. StrSQL = "INSERT INTO tbl_All ( EquipName, AmtRequest, [Min], [Max], AmtReceived, Region, [Zone], Woreda, HealthCenter, ManualExp, AmtShipped, Notes, Supplier ) SELECT '" & EquipmentTbl & "'.EquipName, '" & EquipmentTbl & "'.AmtRequest, '" & EquipmentTbl & "'.Min, '" & EquipmentTbl & "'.Max, '" & EquipmentTbl & "'.AmtReceived, tbl_selectsite.Region, tbl_selectsite.Zone, tbl_selectsite.Woreda, tbl_selectsite.HealthCenter, '" & EquipmentTbl & "'.ManualExp, '" & EquipmentTbl & "'.AmtShipped, '" & EquipmentTbl & "'.Notes, '" & EquipmentTbl & "'.Supplier FROM '" & EquipmentTbl & "', tbl_selectsite;"
  4.  
  5.  
  6. DoCmd.RunSQL (StrSQL)
  7.  
When I run this I get an error that says "Syntax error in query. Incomplete query clause" Can anyone help me decipher what its wrong in the code??

Thanks!
Dec 11 '07 #1
4 5723
Rabbit
12,516 Expert Mod 8TB
Why are you surrounding your table names using single quotes?

Your're doing:
Expand|Select|Wrap|Line Numbers
  1. SELECT 'Table1'.* FROM 'Table1';
  2.  
Do you have spaces in your table names? If you do then you need brackets, [ ], not single quotes.
Dec 11 '07 #2
Why are you surrounding your table names using single quotes?

Your're doing:
Expand|Select|Wrap|Line Numbers
  1. SELECT 'Table1'.* FROM 'Table1';
  2.  
Do you have spaces in your table names? If you do then you need brackets, [ ], not single quotes.

The actual name of my table is not EquipmentTbl. The value of this variable is the name of my table.
Dec 12 '07 #3
FishVal
2,653 Expert 2GB
Hi, there.

What all these single quotes are supposed to mean?
Kill'em to death.

Regards,
Fish

P.S. As Rabbit said - enclose all names breaking Access naming rules in square brackets. If you copypasted exactly the code you have, then the fieldname [Supplier FROM] has a space and must be enclosed in square brackets.
Dec 12 '07 #4
Hi, there.

What all these single quotes are supposed to mean?
Kill'em to death.

Regards,
Fish

P.S. As Rabbit said - enclose all names breaking Access naming rules in square brackets. If you copypasted exactly the code you have, then the fieldname [Supplier FROM] has a space and must be enclosed in square brackets.

Thanks all. It worked.
Dec 12 '07 #5

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

Similar topics

3
by: Paul M. | last post by:
Hi, I am trying to populate 3 paramters in an asp .net (vb) page redirect, the first one is ok ok and gets populated by the other two get inserted into the url for the redirect as empty strings!...
0
by: karinski | last post by:
Hi All, I have a split f/e - b/e setup on my database with RWOP queries on the front end. The code below gets a PO number(s), and vendor name from a multi choice list box on another form. It...
1
by: gtg974p | last post by:
Sub: Append a string to all the values in a column SQL Hi all, This might be a very simple query. But I am new to SQL programming. Hope someone can help me. I have a table --- 1634 ...
4
by: robboll | last post by:
When I try to use an append query from an oracle link it takes forever. I am exploring the idea of doing an append action using a pass-through query. If I have an Oracle ODBC connection to...
1
by: brino | last post by:
hi all ! i needed to append about 20 fields from a query into the 1 field of another table so that i can produce a report. i tried to do this in an append query but it would not work because i...
11
by: kabradley | last post by:
Hello Everyone, So, thanks to nico's help I was finally able to 'finish' our companies access database. For the past week or so though,I have been designing forms that contain a subform and an...
3
by: clarencemo | last post by:
Hello all, I have a append query that works great if I just run the query via Access. I need to convert that query into VBA code. Here is the SQL View of the query I'm trying to convert: ...
2
by: sesling | last post by:
In VB, I have created an append query that will write the results to a table. To each of the records being written, I want to include the user name of the person running the query. I know how to...
4
by: franc sutherland | last post by:
Hello, I am using Access 2003. I am having trouble trapping the "can't append all the records in the append query" error message when appending data to a query from a table which is linked to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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...
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
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.