By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,050 Members | 1,564 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,050 IT Pros & Developers. It's quick & easy.

Inserting records from different source to a single table.

P: 23
hellow Experts,
I have created a table:Temptbl
with this code,
Expand|Select|Wrap|Line Numbers
  1. strCreatetbl = "CREATE TABLE TempTbl " & _
  2.                "(Login TEXT(64), " & _
  3.                "Email TEXT(64), " & _
  4.                "Department TEXT(64), " & _
  5.                "[First name] TEXT(64), " & _
  6.                "[Last name] TEXT(64), " & _
  7.                "Net_Login Text(64) ) "
Now,the first 5 fields are same(by name,value) as my existing table"All_Table".
6th field"Net_Login" is in string:"strvalue".
I need to insert all records from my existing table"all_Table" and also from "strvalue" to the field"Net_Login".
Please suggest me with some sample code.
Thank you
Apr 11 '12 #1
Share this Question
Share on Google+
4 Replies


NeoPa
Expert Mod 15k+
P: 31,494
I suggest you create an Append query (Use the QBE design grid if that's easier for you.) that selects the first 5 fields from [All_Table]. When you have the SQL from that you can use code similar to the following to insert the static value from strValue :
Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2.  
  3. strSQL = "INSERT INTO [TempTbl] (" & _
  4.          "       [Login]," & _
  5.          "       [email]," & _
  6.          "       [Department]," & _
  7.          "       [First Name]," & _
  8.          "       [Last Name]," & _
  9.          "       [Net_Login]) " & _
  10.          "SELECT [Login]," & _
  11.          "       [email]," & _
  12.          "       [Department]," & _
  13.          "       [First Name]," & _
  14.          "       [Last Name]," & _
  15.          "       '%N' AS [Net_Login] "
  16.          "FROM   [All_Table]"
  17. strSQL = Replace(strSQL, "%N", strValue)
Apr 11 '12 #2

P: 23
Thank you sir,
I will definitely use this code.

I am using ADO so can i use this same in my project?

But i am not anything about "QBE design grid".
As per your guideance i will definitely try.
Apr 12 '12 #3

P: 23
Yes sir Neopa, it works with ADo.
It append all my records from All_Table to TempTbl,
But in the field "Net_Login" ,only the last value of strValue displays repetedly.
Number of records in strValue are same as num of All_Table.
Please rectify.
should i loop some where?
Apr 12 '12 #4

NeoPa
Expert Mod 15k+
P: 31,494
QBE = Query By Example. This is simply Design View of a query.

My suggestion doesn't match your requirement, but it does match your question. I cannot give a different solution until you change or clarify the question. Your question indicates you want the same value in every record. If this is not true, then only you know what the question should have been. I can only answer the question you post, regardless of whatever it is you're thinking.
Apr 15 '12 #5

Post your reply

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