473,413 Members | 2,056 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,413 software developers and data experts.

INSERT INTO with mix sources of Field Data and Constant

I need to fill tblA from within VBA code.

Two of the fields in tblB will provide data for two of the fields in tblA.

I think that is pretty straight forward as in:

strInsertSQL = "INSERT INTO tblA(fld1, fld2) " _
& "Select fldA, fldB " _
& "From tblB ;"
DoCmd.RunSQL (strInsertSQL)

Can I, in the same statement, INSERT a repeating Value for fld3.
The Value would be a string equating to the FieldName of fldC in tblB.
I can get the fieldName into a variable, strFldName but do not know
the syntax to include it in the INSERT statement.

Access help file does not help.

I think I could do it with first an INSERT and then an UPDATE but would
prefer
something where the process either succeeds or fails as one.

Thanks in advance for any help.
Oct 3 '06 #1
2 5272

Kc-Mass wrote:
I need to fill tblA from within VBA code.

Two of the fields in tblB will provide data for two of the fields in tblA.

I think that is pretty straight forward as in:

strInsertSQL = "INSERT INTO tblA(fld1, fld2) " _
& "Select fldA, fldB " _
& "From tblB ;"
DoCmd.RunSQL (strInsertSQL)

Can I, in the same statement, INSERT a repeating Value for fld3.
The Value would be a string equating to the FieldName of fldC in tblB.
I can get the fieldName into a variable, strFldName but do not know
the syntax to include it in the INSERT statement.

Access help file does not help.

I think I could do it with first an INSERT and then an UPDATE but would
prefer
something where the process either succeeds or fails as one.

Try something like this:

strText = "foo"
strInsertSQL = _
"INSERT INTO tblA(fld1, fld2, fld3) " _
& "Select fldA, fldB, '" & strText & "' AS Expr1 " _
& "From tblB ;"

Oct 3 '06 #2
Terrific. Thank you very much!
"Gord" <gd*@kingston.netwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
>
Kc-Mass wrote:
>I need to fill tblA from within VBA code.

Two of the fields in tblB will provide data for two of the fields in
tblA.

I think that is pretty straight forward as in:

strInsertSQL = "INSERT INTO tblA(fld1, fld2) " _
& "Select fldA, fldB " _
& "From tblB ;"
DoCmd.RunSQL (strInsertSQL)

Can I, in the same statement, INSERT a repeating Value for fld3.
The Value would be a string equating to the FieldName of fldC in tblB.
I can get the fieldName into a variable, strFldName but do not know
the syntax to include it in the INSERT statement.

Access help file does not help.

I think I could do it with first an INSERT and then an UPDATE but would
prefer
something where the process either succeeds or fails as one.


Try something like this:

strText = "foo"
strInsertSQL = _
"INSERT INTO tblA(fld1, fld2, fld3) " _
& "Select fldA, fldB, '" & strText & "' AS Expr1 " _
& "From tblB ;"

Oct 3 '06 #3

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

Similar topics

19
by: John Keeling | last post by:
Dear all, I tried the test program below. My interest is to examine timing differences between insert vs. append & reverse for a list. My results on my XP Python 2.3.4 are as follows:...
5
by: me | last post by:
I'm also having problems getting the bulk insert to work. I don't know anything about it except what I've gleened from BOL but I'm not seeming to get anywhere...Hopefully there is some little (or...
6
by: Mark P | last post by:
Some time ago I posted here about inserting into a set with a hint: ...
20
by: akej via SQLMonster.com | last post by:
Hi, i have table with 15 columns CREATE TABLE . ( PRIMARY KEY , NULL , NULL , NULL , NULL , (50) NULL , NULL
5
by: Klemens | last post by:
I get SQL30090 reason 18 by trying to do an insert in a federated table and an update in a local table in one transaction Do I have to change some settings to get done or ist this not possible by...
8
by: Carl | last post by:
Hi, I hope someone can share some of their professional advice and help me out with my embarissing problem concerning an Access INSERT query. I have never attempted to create a table with...
24
by: deko | last post by:
I'm trying to log error messages and sometimes (no telling when or where) the message contains a string with double quotes. Is there a way get the query to insert the string with the double...
4
by: jcsnippets.atspace.com | last post by:
Hi everyone, Recently I have posted a question regarding special characters in text files. I was trying to read the text file to process the text later on, but I was using the wrong encoding....
11
by: Ted | last post by:
OK, I tried this: USE Alert_db; BULK INSERT funds FROM 'C:\\data\\myData.dat' WITH (FIELDTERMINATOR='\t', KEEPNULLS, ROWTERMINATOR='\r\n');
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
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.