Results 1 to 6 of 6
  1. #1
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776

    ConCat in a SQL insert into statement?

    Hi all,
    I have the following SQL Insert Into statement and i want to know if I can ConCat txt and another field into this.

    Code:
    Private Sub CmdSubmit_Click()    If IsNull(CboFromAccountID) Or IsNull(CboToAccountID) Then
                MsgBox "You're missing some data!"
                Exit Sub
        End If
        
        Me.TxtTransNumber = [TxtRandom]
        DoCmd.SetWarnings False
        DoCmd.RunSQL "INSERT INTO AccountLedgerTbl (TransID, AccountID, TransDate, TransNumber, Description, Method, Debit) " & _
            "VALUES (" & TxtTransID & ", " & CboFromAccountID & ", #" & TxtTransDate & "#, '" & TxtTransNumber & "', '" & TxtTransType & "', '" & TxtMethod & "' , " & TxtAmount & ")"
        DoCmd.RunSQL "INSERT INTO AccountLedgerTbl (TransID, AccountID, TransDate, TransNumber, Description, Method, Credit) " & _
            "VALUES (" & TxtTransID & ", " & CboToAccountID & ", #" & TxtTransDate & "#, '" & TxtTransNumber & "', '" & TxtTransType & "', '" & TxtMethod & "' , " & TxtAmount & ")"
        DoCmd.SetWarnings True
    
    
        DoCmd.Close
    End Sub
    In the First Values Row of this code, I want to add to the TxtTransType in this line the Txt "To" and CboToAccountID and then do the same on the second Values Row
    TxtTransType in this linethe Txt "From" and CboFromAccountID
    This would be like, TxtTransType (Deposit or Transfer or Purchase or Payment) It would put in Description in tbl "Deposit To Bank of America" and "Deposit From Parkway C&A"
    rather than just Deposit.... Hope this makes sense. I cant figure out how to ConCat that? Basically i want to know is how do i concat (TxtTransType & "To" & CboToAccountID)



    Thanks
    Dave

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    Along the lines of replacing:

    '" & TxtTransType & "'

    with

    '" & TxtTransType & " to " & CboToAccountID & "'
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    thank you,
    This worked however i received the result of
    Deposit to 10
    Deposit from 10
    I received the #10 instead of the txt value of that id?
    Anyway to correct that?
    Thanks

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    If it's a combo you may need to refer to a different column, like:

    CboToAccountID.Column(1)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Geniess! Thank you so much....
    I love it when a plan comes together...
    \Again, thank you
    Dave

  6. #6
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 05-10-2019, 10:40 PM
  2. Insert INTO SQL Statement
    By tecknologikal in forum Programming
    Replies: 3
    Last Post: 02-12-2019, 09:31 PM
  3. INSERT INTO statement
    By berderder in forum Programming
    Replies: 4
    Last Post: 06-03-2016, 06:00 PM
  4. INSERT statement
    By GraeagleBill in forum Programming
    Replies: 2
    Last Post: 03-29-2013, 12:53 PM
  5. Insert statement
    By crowegreg in forum Programming
    Replies: 2
    Last Post: 08-19-2011, 02:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums