G
Guest
Hi, I am pulling my hair out with this Syntax issue, I am trying to load in a
linked Spreadsheet and then append some fields from this into a table that is
sitting on another drive but I am connecting to it via ADO. For some reason
when executing the code it doesnt seem to like my SQL statement and I cant
find out where, or why
Can anyone point me in the right direction?
Private Sub cmdImport_Click()
'cTables is named as a Public Constant (z:\CSITables.mdb)
Dim cnn As ADODB.Connection
Dim sQRY As String
DoCmd.SetWarnings False
strTempTable = "tblCSATAddressTEMP"
strFilePath = Me.txtFilePath
'Check that BusinessType has been selected- quit if not
If IsNull(Me.cboBusinessType) Or Me.cboBusinessType = "" Then
MsgBox "You must select a Business Type from the dropdown list",
vbExclamation, cApplicationName
Exit Sub
End If
If VBA.Len(strFilePath) <> 0 Then
'Import the spreadsheet
DoCmd.TransferSpreadsheet acLink, , strTempTable, strFilePath, True
Set cnn = New ADODB.Connection
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin; " & _
"Data Source=" & cTables
'insert new addresses into tblAddress
sQRY = _
"INSERT INTO tblCSATAddressA IN '" & cTables & "' " & vbCrLf & _
"( JobNumber, Address, ProjectID, Project, JobDate, TeamCode,
Engineer, Contract, BusinessType )" & vbCrLf & _
"SELECT" & vbCrLf & _
"tblCSATAddressTEMP.[No]," & vbCrLf & _
"tblCSATAddressTEMP.Description," & vbCrLf & _
"tblCSATAddressTEMP.[Bill-to Customer No]," & vbCrLf & _
"tblCSATAddressTEMP.[Scheme Code]," & vbCrLf & _
"tblCSATAddressTEMP.[Planned Start Date]," & vbCrLf & _
"tblCSATAddressTEMP.[Team Code]," & vbCrLf & _
"tblFamilyTree.Engineer," & vbCrLf & _
"tblFamilyTree.Contract," & vbCrLf & _
"'" & Me.cboBusinessType & "' AS BusinessType" & vbCrLf & _
"FROM tblCSATAddressTEMP " & vbCrLf & _
"LEFT JOIN tblFamilyTree ON tblCSATAddressTEMP.[Team Code] =
tblFamilyTree.TeamCode"
CurrentProject.Connection.Execute sQRY
End If
'DoCmd.DeleteObject acTable, strTempTable
MsgBox Me.cboBusinessType & " Data has been imported",
vbExclamation, cApplicationName
cnn.Close
Set cnn = Nothing
Exit Sub
End Sub
linked Spreadsheet and then append some fields from this into a table that is
sitting on another drive but I am connecting to it via ADO. For some reason
when executing the code it doesnt seem to like my SQL statement and I cant
find out where, or why
Can anyone point me in the right direction?
Private Sub cmdImport_Click()
'cTables is named as a Public Constant (z:\CSITables.mdb)
Dim cnn As ADODB.Connection
Dim sQRY As String
DoCmd.SetWarnings False
strTempTable = "tblCSATAddressTEMP"
strFilePath = Me.txtFilePath
'Check that BusinessType has been selected- quit if not
If IsNull(Me.cboBusinessType) Or Me.cboBusinessType = "" Then
MsgBox "You must select a Business Type from the dropdown list",
vbExclamation, cApplicationName
Exit Sub
End If
If VBA.Len(strFilePath) <> 0 Then
'Import the spreadsheet
DoCmd.TransferSpreadsheet acLink, , strTempTable, strFilePath, True
Set cnn = New ADODB.Connection
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin; " & _
"Data Source=" & cTables
'insert new addresses into tblAddress
sQRY = _
"INSERT INTO tblCSATAddressA IN '" & cTables & "' " & vbCrLf & _
"( JobNumber, Address, ProjectID, Project, JobDate, TeamCode,
Engineer, Contract, BusinessType )" & vbCrLf & _
"SELECT" & vbCrLf & _
"tblCSATAddressTEMP.[No]," & vbCrLf & _
"tblCSATAddressTEMP.Description," & vbCrLf & _
"tblCSATAddressTEMP.[Bill-to Customer No]," & vbCrLf & _
"tblCSATAddressTEMP.[Scheme Code]," & vbCrLf & _
"tblCSATAddressTEMP.[Planned Start Date]," & vbCrLf & _
"tblCSATAddressTEMP.[Team Code]," & vbCrLf & _
"tblFamilyTree.Engineer," & vbCrLf & _
"tblFamilyTree.Contract," & vbCrLf & _
"'" & Me.cboBusinessType & "' AS BusinessType" & vbCrLf & _
"FROM tblCSATAddressTEMP " & vbCrLf & _
"LEFT JOIN tblFamilyTree ON tblCSATAddressTEMP.[Team Code] =
tblFamilyTree.TeamCode"
CurrentProject.Connection.Execute sQRY
End If
'DoCmd.DeleteObject acTable, strTempTable
MsgBox Me.cboBusinessType & " Data has been imported",
vbExclamation, cApplicationName
cnn.Close
Set cnn = Nothing
Exit Sub
End Sub