Inserting records from different source to a single table.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • usha2
    New Member
    • Mar 2012
    • 23

    Inserting records from different source to a single table.

    hellow Experts,
    I have created a table:Temptbl
    with this code,
    Code:
    strCreatetbl = "CREATE TABLE TempTbl " & _
                   "(Login TEXT(64), " & _
                   "Email TEXT(64), " & _
                   "Department TEXT(64), " & _
                   "[First name] TEXT(64), " & _
                   "[Last name] TEXT(64), " & _
                   "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:"strvalu e".
    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
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32633

    #2
    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 :
    Code:
    Dim strSQL As String
    
    strSQL = "INSERT INTO [TempTbl] (" & _
             "       [Login]," & _
             "       [Email]," & _
             "       [Department]," & _
             "       [First Name]," & _
             "       [Last Name]," & _
             "       [Net_Login]) " & _
             "SELECT [Login]," & _
             "       [Email]," & _
             "       [Department]," & _
             "       [First Name]," & _
             "       [Last Name]," & _
             "       '%N' AS [Net_Login] "
             "FROM   [All_Table]"
    strSQL = Replace(strSQL, "%N", strValue)

    Comment

    • usha2
      New Member
      • Mar 2012
      • 23

      #3
      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.

      Comment

      • usha2
        New Member
        • Mar 2012
        • 23

        #4
        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?

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32633

          #5
          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.

          Comment

          Working...