I have this code that when it run it will import the Spreadsheet into a TEMP table and then I want it to INSERT INTO my Live table.
The problem I have is that it will only create a TEMP table on the Access DB and not import into the SQL Server...
Where have I gone wrong?
The problem I have is that it will only create a TEMP table on the Access DB and not import into the SQL Server...
Where have I gone wrong?
Code:
Private Sub cmdImport_Click()
Dim cnn As ADODB.Connection
Dim strFilePath As String
Dim sQRY As String
Dim strTempTable As String
'*************************************************************************************
Set cnn = New ADODB.Connection
cnn.Open "Driver={SQL Server};Server=CISSQL1;Database=PODIATRY LIVE;Trusted_Connection=Yes"
'*************************************************************************************
On Error GoTo Err
DoCmd.SetWarnings False
strTempTable = "HAH_AppointmentsTEMP"
strFilePath = Me.txtFilePath
If VBA.Len(strFilePath) <> 0 Then
'Import the spreadsheet
DoCmd.TransferSpreadsheet acLink, , strTempTable, strFilePath, True
'*************************************************************************************
sQRY = "INSERT INTO HAH_StaffRota ([StaffName], [DayOfWeek], [RotaDate], [StartTime], [FinishTime]) " & _
"SELECT Name, Day, Date, Start Time, Finish Time " & _
"FROM HAH_AppointmentsTEMP "
cnn.Execute sQRY
'*************************************************************************************
End If
DoCmd.DeleteObject acTable, strTempTable
MsgBox "Data has been imported", vbExclamation, cApplicationName
cnn.Close
Set cnn = Nothing
Exit Sub
Err:
MsgBox VBA.Error$
End Sub