SQL Insert Into Statement

D

Doctorjones_md

I have an Excel workbook with VBA coded Insert Into statment to upload data
to SQL Server.

I'm having a problem with the syntax for creating a line continuation in my
SQL Insert Into statement. I need to add some Field Names to the statement,
but I've reached the max length of the statement. I'm trying to enter a
line continuation after Field AZ (so that I can add the (2) additional
fields -- Here's my code:
====================
Sub InsertData()
Dim oConn As Object
'Dim closed As String
Dim sSQL As String
Application.ScreenUpdating = False

UnhideTrackingOverall

If Sheets("Analysis").Range("D8").Value = ("Default Rep") Then
MsgBox ("You must select your name from the drop-down menu in
cell D8"), vbInformation
Exit Sub

End If

If Sheets("Analysis").Range("D6").Value = ("Sample Customer") Then
MsgBox ("You must enter a Customer Name in cell D6"),
vbInformation
Exit Sub

End If

If Sheets("Analysis").Range("D7").Value = ("111111") Then
MsgBox ("You must enter a valid Customer Number in cell D7"),
vbInformation
Exit Sub

End If

If MsgBox("Is this a Closed Deal?", vbQuestion + vbYesNo) = vbYes
Then


ThisWorkbook.Worksheets("Analysis").Range("D10").Select
'Selection.NumberFormat = "General"

Sheets("Analysis").Range("D10").Value = "Won"

End If

On Error Resume Next


Set wsSheet = ActiveWorkbook.Sheets("Tracking Overall")
Set oConn = CreateObject("ADODB.Connection")
oConn.Open = "Provider=sqloledb;" & _
"Data Source=xx.x.xx.xx;" & _
"Initial Catalog=Products;" & _
"User Id=xxxxxx;" & _
"Password=xxxxxx"
sSQL = "INSERT INTO Products" & _
"([Field A], [Field B], [Field C], [Field D], [Field E], [Field F], [Field
G], [Field H], [Field I], [Field J], [Field K], [Field L], [Field M
(Months)], [Field N], [Field O], [Field P], [Field Q], [Field R], [Field S],
[Field T], [Field U], [Field V], [Field W], [Field X], [Field Y], [Field Z],
[Field AA], [Field AB], [Field AC], [Field AD], [Field AE], [Field AF],
[Field AG], [Field AH], [Field AI], [Field AJ], [Field AK], [Field AL],
[Field AM], [Field AN (Weeks)], [Field AO], [Field AP], [Field AQ], [Field
AR], [Field AS], [Field AT], [Field AU], [Field AV], [Field AW], [Field AX],
[Field AY], [Field AZ], [Field BA], [Field BB], [Field BC], [Field BD],
[Field BE], [Field BF], [Field BG], [Field BH], [Field BI], [Field BJ],
[Field BK], [Field BL], [Field BM])" & _
" VALUES ('" & Range("A2").Value & "', '" & Range("B2").Value & "', '" &
Range("C2").Value & "', '" & Range("D2").Value & "', '" & Range("E2").Value
& "', '" & _
Range("F2").Value & "', '" & Range("G2").Value & "', '" &
Range("H2").Value & "', '" & Range("I2").Value & "', '" & Range("J2").Value
& "', '" & _
Range("K2").Value & "', '" & Range("L2").Value & "', '" &
Range("M2").Value & "', '" & Range("N2").Value & "', '" & Range("O2").Value
& "', '" & _
Range("P2").Value & "', '" & Range("Q2").Value & "', '" &
Range("R2").Value & "', '" & Range("S2").Value & "', '" & Range("T2").Value
& "', '" & _
Range("U2").Value & "', '" & Range("V2").Value2 & "', '" &
Range("W2").Value2 & "', '" & Range("X2").Value2 & "', '" &
Range("Y2").Value2 & "', '" & _
Range("Z2").Value2 & "', '" & Range("AA2").Value2 & "', '" &
Range("AB2").Value2 & "', '" & Range("AC2").Value2 & "', '" &
Range("AD2").Value2 & "', '" & _
Range("AE2").Value2 & "', '" & Range("AF2").Value2 & "', '" &
Range("AG2").Value2 & "', '" & Range("AH2").Value & "', '" &
Range("AI2").Value & "', '" & _
Range("AJ2").Value2 & "', '" & Range("AK2").Value & "', '" &
Range("AL2").Value2 & "', '" & Range("AM2").Value & "', '" &
Range("AN2").Value & "', '" & _
Range("AO2").Value & "', '" & Range("AP2").Value & "', '" &
Range("AQ2").Value & "', '" & Range("AR2").Value & "', '" &
Range("AS2").Value & "', '" & _
Range("AT2").Value & "', '" & Range("AU2").Value & "', '" &
Range("AV2").Value & "', '" & Range("AW2").Value & "', '" &
Range("AX2").Value & "', '" & _
Range("AY2").Value & "', '" & Range("AZ2").Value & "', '" &
Range("BA2").Value & "', '" & Range("BB2").Value & "', '" &
Range("BC2").Value & "', '" & _
Range("BD2").Value & "', '" & Range("BE2").Value & "', '" &
Range("BF2").Value & "', '" & Range("BG2").Value2 & "', '" &
Range("BH2").Value & "', '" & _
Range("BI2").Value & "', '" & Range("BJ2").Value & "', '" &
Range("BK2").Value & "', '" & Range("BL2").Value & "', '" &
Range("BM2").Value & "')"
oConn.Execute sSQL

'Close The Connection
oConn.Close
Set oConn = Nothing

UnhideTrackingSpecific
UnhideRollupSS
UnhideRollupSS1
'UnHideRollupSS3
SQLRollup
RollupToSQLServer1
InsertTrackingSpecificData
HideTrackingOverallData
HideRollupSS
HideRollupSS1
HideTrackingSpecific
HideTrackingOverallData
HideVersionTab

MsgBox ("Upload Complete."), vbInformation

frmProposal_SOF.Show



End Sub
===========================
Many thanks (in advance) for any assistance on this one.

Shane
 
M

MH

Are you getting any kind of error message which might provide useful
information?

MH

Doctorjones_md said:
I have an Excel workbook with VBA coded Insert Into statment to upload data
to SQL Server.

I'm having a problem with the syntax for creating a line continuation in
my SQL Insert Into statement. I need to add some Field Names to the
statement, but I've reached the max length of the statement. I'm trying
to enter a line continuation after Field AZ (so that I can add the (2)
additional fields -- Here's my code:
====================
Sub InsertData()
Dim oConn As Object
'Dim closed As String
Dim sSQL As String
Application.ScreenUpdating = False

UnhideTrackingOverall

If Sheets("Analysis").Range("D8").Value = ("Default Rep") Then
MsgBox ("You must select your name from the drop-down menu in
cell D8"), vbInformation
Exit Sub

End If

If Sheets("Analysis").Range("D6").Value = ("Sample Customer") Then
MsgBox ("You must enter a Customer Name in cell D6"),
vbInformation
Exit Sub

End If

If Sheets("Analysis").Range("D7").Value = ("111111") Then
MsgBox ("You must enter a valid Customer Number in cell D7"),
vbInformation
Exit Sub

End If

If MsgBox("Is this a Closed Deal?", vbQuestion + vbYesNo) = vbYes
Then


ThisWorkbook.Worksheets("Analysis").Range("D10").Select
'Selection.NumberFormat = "General"

Sheets("Analysis").Range("D10").Value = "Won"

End If

On Error Resume Next


Set wsSheet = ActiveWorkbook.Sheets("Tracking Overall")
Set oConn = CreateObject("ADODB.Connection")
oConn.Open = "Provider=sqloledb;" & _
"Data Source=xx.x.xx.xx;" & _
"Initial Catalog=Products;" & _
"User Id=xxxxxx;" & _
"Password=xxxxxx"
sSQL = "INSERT INTO Products" & _
"([Field A], [Field B], [Field C], [Field D], [Field E], [Field F], [Field
G], [Field H], [Field I], [Field J], [Field K], [Field L], [Field M
(Months)], [Field N], [Field O], [Field P], [Field Q], [Field R], [Field
S], [Field T], [Field U], [Field V], [Field W], [Field X], [Field Y],
[Field Z], [Field AA], [Field AB], [Field AC], [Field AD], [Field AE],
[Field AF], [Field AG], [Field AH], [Field AI], [Field AJ], [Field AK],
[Field AL], [Field AM], [Field AN (Weeks)], [Field AO], [Field AP], [Field
AQ], [Field AR], [Field AS], [Field AT], [Field AU], [Field AV], [Field
AW], [Field AX], [Field AY], [Field AZ], [Field BA], [Field BB], [Field
BC], [Field BD], [Field BE], [Field BF], [Field BG], [Field BH], [Field
BI], [Field BJ], [Field BK], [Field BL], [Field BM])" & _
" VALUES ('" & Range("A2").Value & "', '" & Range("B2").Value & "', '"
& Range("C2").Value & "', '" & Range("D2").Value & "', '" &
Range("E2").Value & "', '" & _
Range("F2").Value & "', '" & Range("G2").Value & "', '" &
Range("H2").Value & "', '" & Range("I2").Value & "', '" &
Range("J2").Value & "', '" & _
Range("K2").Value & "', '" & Range("L2").Value & "', '" &
Range("M2").Value & "', '" & Range("N2").Value & "', '" &
Range("O2").Value & "', '" & _
Range("P2").Value & "', '" & Range("Q2").Value & "', '" &
Range("R2").Value & "', '" & Range("S2").Value & "', '" &
Range("T2").Value & "', '" & _
Range("U2").Value & "', '" & Range("V2").Value2 & "', '" &
Range("W2").Value2 & "', '" & Range("X2").Value2 & "', '" &
Range("Y2").Value2 & "', '" & _
Range("Z2").Value2 & "', '" & Range("AA2").Value2 & "', '" &
Range("AB2").Value2 & "', '" & Range("AC2").Value2 & "', '" &
Range("AD2").Value2 & "', '" & _
Range("AE2").Value2 & "', '" & Range("AF2").Value2 & "', '" &
Range("AG2").Value2 & "', '" & Range("AH2").Value & "', '" &
Range("AI2").Value & "', '" & _
Range("AJ2").Value2 & "', '" & Range("AK2").Value & "', '" &
Range("AL2").Value2 & "', '" & Range("AM2").Value & "', '" &
Range("AN2").Value & "', '" & _
Range("AO2").Value & "', '" & Range("AP2").Value & "', '" &
Range("AQ2").Value & "', '" & Range("AR2").Value & "', '" &
Range("AS2").Value & "', '" & _
Range("AT2").Value & "', '" & Range("AU2").Value & "', '" &
Range("AV2").Value & "', '" & Range("AW2").Value & "', '" &
Range("AX2").Value & "', '" & _
Range("AY2").Value & "', '" & Range("AZ2").Value & "', '" &
Range("BA2").Value & "', '" & Range("BB2").Value & "', '" &
Range("BC2").Value & "', '" & _
Range("BD2").Value & "', '" & Range("BE2").Value & "', '" &
Range("BF2").Value & "', '" & Range("BG2").Value2 & "', '" &
Range("BH2").Value & "', '" & _
Range("BI2").Value & "', '" & Range("BJ2").Value & "', '" &
Range("BK2").Value & "', '" & Range("BL2").Value & "', '" &
Range("BM2").Value & "')"
oConn.Execute sSQL

'Close The Connection
oConn.Close
Set oConn = Nothing

UnhideTrackingSpecific
UnhideRollupSS
UnhideRollupSS1
'UnHideRollupSS3
SQLRollup
RollupToSQLServer1
InsertTrackingSpecificData
HideTrackingOverallData
HideRollupSS
HideRollupSS1
HideTrackingSpecific
HideTrackingOverallData
HideVersionTab

MsgBox ("Upload Complete."), vbInformation

frmProposal_SOF.Show



End Sub
===========================
Many thanks (in advance) for any assistance on this one.

Shane
 
D

Doctorjones_md

The Insert Into statement (that I've pasted below) works fine as it is, but
I need to add (2) fields to the statement, and I've reached the Max
Character Limit for the line -- I need help with the syntax for a line
continuation -- sorry if this request is confusing -- I just can't seem to
be able to extend beyond the character limit. I hope I'm making sense with
this explanation.

Thanks for your prompt reply.

Shane
MH said:
Are you getting any kind of error message which might provide useful
information?

MH

Doctorjones_md said:
I have an Excel workbook with VBA coded Insert Into statment to upload
data to SQL Server.

I'm having a problem with the syntax for creating a line continuation in
my SQL Insert Into statement. I need to add some Field Names to the
statement, but I've reached the max length of the statement. I'm trying
to enter a line continuation after Field AZ (so that I can add the (2)
additional fields -- Here's my code:
====================
Sub InsertData()
Dim oConn As Object
'Dim closed As String
Dim sSQL As String
Application.ScreenUpdating = False

UnhideTrackingOverall

If Sheets("Analysis").Range("D8").Value = ("Default Rep") Then
MsgBox ("You must select your name from the drop-down menu in
cell D8"), vbInformation
Exit Sub

End If

If Sheets("Analysis").Range("D6").Value = ("Sample Customer") Then
MsgBox ("You must enter a Customer Name in cell D6"),
vbInformation
Exit Sub

End If

If Sheets("Analysis").Range("D7").Value = ("111111") Then
MsgBox ("You must enter a valid Customer Number in cell D7"),
vbInformation
Exit Sub

End If

If MsgBox("Is this a Closed Deal?", vbQuestion + vbYesNo) = vbYes
Then


ThisWorkbook.Worksheets("Analysis").Range("D10").Select
'Selection.NumberFormat = "General"

Sheets("Analysis").Range("D10").Value = "Won"

End If

On Error Resume Next


Set wsSheet = ActiveWorkbook.Sheets("Tracking Overall")
Set oConn = CreateObject("ADODB.Connection")
oConn.Open = "Provider=sqloledb;" & _
"Data Source=xx.x.xx.xx;" & _
"Initial Catalog=Products;" & _
"User Id=xxxxxx;" & _
"Password=xxxxxx"
sSQL = "INSERT INTO Products" & _
"([Field A], [Field B], [Field C], [Field D], [Field E], [Field F],
[Field G], [Field H], [Field I], [Field J], [Field K], [Field L], [Field
M (Months)], [Field N], [Field O], [Field P], [Field Q], [Field R],
[Field S], [Field T], [Field U], [Field V], [Field W], [Field X], [Field
Y], [Field Z], [Field AA], [Field AB], [Field AC], [Field AD], [Field
AE], [Field AF], [Field AG], [Field AH], [Field AI], [Field AJ], [Field
AK], [Field AL], [Field AM], [Field AN (Weeks)], [Field AO], [Field AP],
[Field AQ], [Field AR], [Field AS], [Field AT], [Field AU], [Field AV],
[Field AW], [Field AX], [Field AY], [Field AZ], [Field BA], [Field BB],
[Field BC], [Field BD], [Field BE], [Field BF], [Field BG], [Field BH],
[Field BI], [Field BJ], [Field BK], [Field BL], [Field BM])" & _
" VALUES ('" & Range("A2").Value & "', '" & Range("B2").Value & "', '"
& Range("C2").Value & "', '" & Range("D2").Value & "', '" &
Range("E2").Value & "', '" & _
Range("F2").Value & "', '" & Range("G2").Value & "', '" &
Range("H2").Value & "', '" & Range("I2").Value & "', '" &
Range("J2").Value & "', '" & _
Range("K2").Value & "', '" & Range("L2").Value & "', '" &
Range("M2").Value & "', '" & Range("N2").Value & "', '" &
Range("O2").Value & "', '" & _
Range("P2").Value & "', '" & Range("Q2").Value & "', '" &
Range("R2").Value & "', '" & Range("S2").Value & "', '" &
Range("T2").Value & "', '" & _
Range("U2").Value & "', '" & Range("V2").Value2 & "', '" &
Range("W2").Value2 & "', '" & Range("X2").Value2 & "', '" &
Range("Y2").Value2 & "', '" & _
Range("Z2").Value2 & "', '" & Range("AA2").Value2 & "', '" &
Range("AB2").Value2 & "', '" & Range("AC2").Value2 & "', '" &
Range("AD2").Value2 & "', '" & _
Range("AE2").Value2 & "', '" & Range("AF2").Value2 & "', '" &
Range("AG2").Value2 & "', '" & Range("AH2").Value & "', '" &
Range("AI2").Value & "', '" & _
Range("AJ2").Value2 & "', '" & Range("AK2").Value & "', '" &
Range("AL2").Value2 & "', '" & Range("AM2").Value & "', '" &
Range("AN2").Value & "', '" & _
Range("AO2").Value & "', '" & Range("AP2").Value & "', '" &
Range("AQ2").Value & "', '" & Range("AR2").Value & "', '" &
Range("AS2").Value & "', '" & _
Range("AT2").Value & "', '" & Range("AU2").Value & "', '" &
Range("AV2").Value & "', '" & Range("AW2").Value & "', '" &
Range("AX2").Value & "', '" & _
Range("AY2").Value & "', '" & Range("AZ2").Value & "', '" &
Range("BA2").Value & "', '" & Range("BB2").Value & "', '" &
Range("BC2").Value & "', '" & _
Range("BD2").Value & "', '" & Range("BE2").Value & "', '" &
Range("BF2").Value & "', '" & Range("BG2").Value2 & "', '" &
Range("BH2").Value & "', '" & _
Range("BI2").Value & "', '" & Range("BJ2").Value & "', '" &
Range("BK2").Value & "', '" & Range("BL2").Value & "', '" &
Range("BM2").Value & "')"
oConn.Execute sSQL

'Close The Connection
oConn.Close
Set oConn = Nothing

UnhideTrackingSpecific
UnhideRollupSS
UnhideRollupSS1
'UnHideRollupSS3
SQLRollup
RollupToSQLServer1
InsertTrackingSpecificData
HideTrackingOverallData
HideRollupSS
HideRollupSS1
HideTrackingSpecific
HideTrackingOverallData
HideVersionTab

MsgBox ("Upload Complete."), vbInformation

frmProposal_SOF.Show



End Sub
===========================
Many thanks (in advance) for any assistance on this one.

Shane
 
M

MH

If you have:

"([Field A], [Field B], [Field C], [Field D], [Field E], [Field F], [Field
G])"

And you want to split it over two lines, you would use:

"([Field A], [Field B], [Field C], [Field D], " & _
"[Field E], [Field F], [Field G])"

Which is a technique you are already using in your sSQL variable.

MH

Doctorjones_md said:
The Insert Into statement (that I've pasted below) works fine as it is,
but I need to add (2) fields to the statement, and I've reached the Max
Character Limit for the line -- I need help with the syntax for a line
continuation -- sorry if this request is confusing -- I just can't seem to
be able to extend beyond the character limit. I hope I'm making sense
with this explanation.

Thanks for your prompt reply.

Shane
MH said:
Are you getting any kind of error message which might provide useful
information?

MH

Doctorjones_md said:
I have an Excel workbook with VBA coded Insert Into statment to upload
data to SQL Server.

I'm having a problem with the syntax for creating a line continuation in
my SQL Insert Into statement. I need to add some Field Names to the
statement, but I've reached the max length of the statement. I'm trying
to enter a line continuation after Field AZ (so that I can add the (2)
additional fields -- Here's my code:
====================
Sub InsertData()
Dim oConn As Object
'Dim closed As String
Dim sSQL As String
Application.ScreenUpdating = False

UnhideTrackingOverall

If Sheets("Analysis").Range("D8").Value = ("Default Rep") Then
MsgBox ("You must select your name from the drop-down menu in
cell D8"), vbInformation
Exit Sub

End If

If Sheets("Analysis").Range("D6").Value = ("Sample Customer")
Then
MsgBox ("You must enter a Customer Name in cell D6"),
vbInformation
Exit Sub

End If

If Sheets("Analysis").Range("D7").Value = ("111111") Then
MsgBox ("You must enter a valid Customer Number in cell D7"),
vbInformation
Exit Sub

End If

If MsgBox("Is this a Closed Deal?", vbQuestion + vbYesNo) = vbYes
Then


ThisWorkbook.Worksheets("Analysis").Range("D10").Select
'Selection.NumberFormat = "General"

Sheets("Analysis").Range("D10").Value = "Won"

End If

On Error Resume Next


Set wsSheet = ActiveWorkbook.Sheets("Tracking Overall")
Set oConn = CreateObject("ADODB.Connection")
oConn.Open = "Provider=sqloledb;" & _
"Data Source=xx.x.xx.xx;" & _
"Initial Catalog=Products;" & _
"User Id=xxxxxx;" & _
"Password=xxxxxx"
sSQL = "INSERT INTO Products" & _
"([Field A], [Field B], [Field C], [Field D], [Field E], [Field F],
[Field G], [Field H], [Field I], [Field J], [Field K], [Field L], [Field
M (Months)], [Field N], [Field O], [Field P], [Field Q], [Field R],
[Field S], [Field T], [Field U], [Field V], [Field W], [Field X], [Field
Y], [Field Z], [Field AA], [Field AB], [Field AC], [Field AD], [Field
AE], [Field AF], [Field AG], [Field AH], [Field AI], [Field AJ],
[Field AK], [Field AL], [Field AM], [Field AN (Weeks)], [Field AO],
[Field AP], [Field AQ], [Field AR], [Field AS], [Field AT], [Field AU],
[Field AV], [Field AW], [Field AX], [Field AY], [Field AZ], [Field BA],
[Field BB], [Field BC], [Field BD], [Field BE], [Field BF], [Field BG],
[Field BH], [Field BI], [Field BJ], [Field BK], [Field BL], [Field BM])"
& _
" VALUES ('" & Range("A2").Value & "', '" & Range("B2").Value & "',
'" & Range("C2").Value & "', '" & Range("D2").Value & "', '" &
Range("E2").Value & "', '" & _
Range("F2").Value & "', '" & Range("G2").Value & "', '" &
Range("H2").Value & "', '" & Range("I2").Value & "', '" &
Range("J2").Value & "', '" & _
Range("K2").Value & "', '" & Range("L2").Value & "', '" &
Range("M2").Value & "', '" & Range("N2").Value & "', '" &
Range("O2").Value & "', '" & _
Range("P2").Value & "', '" & Range("Q2").Value & "', '" &
Range("R2").Value & "', '" & Range("S2").Value & "', '" &
Range("T2").Value & "', '" & _
Range("U2").Value & "', '" & Range("V2").Value2 & "', '" &
Range("W2").Value2 & "', '" & Range("X2").Value2 & "', '" &
Range("Y2").Value2 & "', '" & _
Range("Z2").Value2 & "', '" & Range("AA2").Value2 & "', '" &
Range("AB2").Value2 & "', '" & Range("AC2").Value2 & "', '" &
Range("AD2").Value2 & "', '" & _
Range("AE2").Value2 & "', '" & Range("AF2").Value2 & "', '" &
Range("AG2").Value2 & "', '" & Range("AH2").Value & "', '" &
Range("AI2").Value & "', '" & _
Range("AJ2").Value2 & "', '" & Range("AK2").Value & "', '" &
Range("AL2").Value2 & "', '" & Range("AM2").Value & "', '" &
Range("AN2").Value & "', '" & _
Range("AO2").Value & "', '" & Range("AP2").Value & "', '" &
Range("AQ2").Value & "', '" & Range("AR2").Value & "', '" &
Range("AS2").Value & "', '" & _
Range("AT2").Value & "', '" & Range("AU2").Value & "', '" &
Range("AV2").Value & "', '" & Range("AW2").Value & "', '" &
Range("AX2").Value & "', '" & _
Range("AY2").Value & "', '" & Range("AZ2").Value & "', '" &
Range("BA2").Value & "', '" & Range("BB2").Value & "', '" &
Range("BC2").Value & "', '" & _
Range("BD2").Value & "', '" & Range("BE2").Value & "', '" &
Range("BF2").Value & "', '" & Range("BG2").Value2 & "', '" &
Range("BH2").Value & "', '" & _
Range("BI2").Value & "', '" & Range("BJ2").Value & "', '" &
Range("BK2").Value & "', '" & Range("BL2").Value & "', '" &
Range("BM2").Value & "')"
oConn.Execute sSQL

'Close The Connection
oConn.Close
Set oConn = Nothing

UnhideTrackingSpecific
UnhideRollupSS
UnhideRollupSS1
'UnHideRollupSS3
SQLRollup
RollupToSQLServer1
InsertTrackingSpecificData
HideTrackingOverallData
HideRollupSS
HideRollupSS1
HideTrackingSpecific
HideTrackingOverallData
HideVersionTab

MsgBox ("Upload Complete."), vbInformation

frmProposal_SOF.Show



End Sub
===========================
Many thanks (in advance) for any assistance on this one.

Shane
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top