Assistance needed in sql syntax while breaking code into multiple lines (1 Viewer)

Voyager

Registered User.
Local time
Today, 21:53
Joined
Sep 7, 2017
Messages
95
Hi isladogs,
Yes I see that as my responsibility to post the right one which is yours. Your code in #16 not only solved my problem but also gives multiple ways to solve the issue. Great one. I like uncle gizmos version too. Multiple suggestion in this post really good one.

Code:
updsql = “ insert into tasks ( received, sender, [sent at],"
updsql = updsql & “ employee, department )”
updsql = updsql & “ values (#” & me.rvd & “#, ‘“ & me.snd & “‘,”
updsql = updsql & “ ‘“ & me.sntat & “‘,” 
updsql = updsql & “ ‘“ & me.emp & “‘, ‘“ & me.dpt & “‘);”
 

Mark_

Longboard on the internet
Local time
Today, 09:23
Joined
Sep 12, 2017
Messages
2,111
Though not required, I'd personally use a parameter driven insert.
Code:
Dim asSQL As String
asSQL = "Insert Into Tasks (" & _
    " Received," & _
    " Sender," & _
    " [Sent at]," & _
    " Employee," & _
    " Department)"
    
asSQL = asSQL & " SELECT p01, p02, p03,p04,p05"

    With CurrentDb.CreateQueryDef("", asSQL)
        .Parameters(0) = me.rvd
        .Parameters(1) = me.snd
        .Parameters(2) = me.sntat
        .Parameters(3) = me.emp
        .Parameters(4) = me.dpt
        .Execute
    End With

Biggest advantage is that you get ACCESS to worry about formatting dates and such. Also supports having single or double quotes in data.

Arnel posted a more elaborate function to do this, but I find it more intuitive when coding to spell it out so I won't forget what I'm doing.
 

Users who are viewing this thread

Top Bottom