473,386 Members | 1,830 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,386 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 5270

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
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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,...

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.