Sanjay
asked on
a column is not importing date data into a linked sql table
I am importing data from an excel file (Stock_Status_Report.xls) into a linked SQL table in my MS access application. The linked table is called dbo_Stock_Status_Report. This SQL table has a field called "Next Delivery Date". The excel file also has the same field name. The docmd.transferspreadsheet method imports all of the data except for the date data in the column Next Delivery Date with no errors. I have no idea why this is happening. COuld really use expert help.
Sub Excel_Import_Stock()
Dim table1 As String, table2 As String, table3 As String
Dim db As DAO.Database
Dim tbl As DAO.TableDef
Dim indx As DAO.Index
Dim PrimaryKey As String
Dim qry As String
Dim xlObj As Excel.Application
Dim shtName As String
Dim xlPath As String, xlFile As String
Dim filArr(), j
DoCmd.SetWarnings False
table1 = "dbo_Stock_Status_Report"
table2 = "dbo_On_Hand_Value"
SaveEmailAttachments_Stock 'SAVES OHM E-MAIL EXCEL ATTACHMENTS TO DESKTOP
Excel_Rename_Columns
filArr = Array("Stock_Status_Report .xls", "On_Hand_Value.xls")
xlPath = GetUSERPROFILE() & "\Desktop"
Set xlObj = CreateObject("Excel.Applic ation")
'import the excel file
For j = LBound(filArr) To UBound(filArr)
xlObj.Workbooks.Open xlPath & "\" & filArr(j)
shtName = xlObj.Worksheets(1).Name
If filArr(j) = "Stock_Status_Report.xls" Then
DoCmd.RunSQL "DELETE * FROM " & table1
DoCmd.TransferSpreadsheet acImport, , table1, xlPath & "\" & filArr(j), True, shtName & "!"
' ElseIf filArr(j) = "On_Hand_Value.xls" Then
' DoCmd.RunSQL "DELETE * FROM " & table2
' DoCmd.TransferSpreadsheet acImport, , table2, xlPath & "\" & filArr(j), True, shtName & "!"
End If
Next
For j = LBound(filArr) To UBound(filArr)
xlObj.Workbooks.Close
Set xlObj = Nothing
On Error Resume Next
Kill xlPath & "\" & filArr(j) 'Delete the Excel files
Next
xlObj.Workbooks.Close
Set xlObj = Nothing
TerminateExcelProcess
'x_DropStockImportErrorsTa bles
'Add_Current_Date_Time
DoCmd.SetWarnings True
MsgBox "Stock data import complete."
End Sub
Sub Excel_Rename_Columns()
Dim xlObj As Excel.Application
Dim xlPath As String, shtName As String
Dim filArr(), j
Dim i As Integer
DoCmd.SetWarnings False
filArr = Array("Stock_Status_Report .xls")
xlPath = "C:\Users\sanjayg\Desktop"
Set xlObj = CreateObject("Excel.Applic ation")
For j = LBound(filArr) To UBound(filArr)
xlObj.Workbooks.Open xlPath & "\" & filArr(j)
shtName = xlObj.Worksheets(1).Name
For i = 1 To xlObj.Worksheets(shtName). UsedRange. Columns.Co unt
If xlObj.Worksheets(shtName). Cells(1, i).Value = "Description" Then
xlObj.Worksheets(shtName). Cells(1, i).Value = "Desc"
ElseIf xlObj.Worksheets(shtName). Cells(1, i).Value = "Annual Dep. Usage" Then
xlObj.Worksheets(shtName). Cells(1, i).Value = "Annual Dep Usage"
ElseIf xlObj.Worksheets(shtName). Cells(1, i).Value = "Annual Indep. Usage" Then
xlObj.Worksheets(shtName). Cells(1, i).Value = "Annual Indep Usage"
End If
Next
xlObj.Worksheets(shtName). Columns("H :H").Numbe rFormat = "m/d/yyyy"
Next
xlObj.ActiveWorkbook.Save
'xlObj.Workbooks.Close
Set xlObj = Nothing
TerminateExcelProcess
'DoCmd.SetWarnings True
End Sub
Sub Excel_Import_Stock()
Dim table1 As String, table2 As String, table3 As String
Dim db As DAO.Database
Dim tbl As DAO.TableDef
Dim indx As DAO.Index
Dim PrimaryKey As String
Dim qry As String
Dim xlObj As Excel.Application
Dim shtName As String
Dim xlPath As String, xlFile As String
Dim filArr(), j
DoCmd.SetWarnings False
table1 = "dbo_Stock_Status_Report"
table2 = "dbo_On_Hand_Value"
SaveEmailAttachments_Stock
Excel_Rename_Columns
filArr = Array("Stock_Status_Report
xlPath = GetUSERPROFILE() & "\Desktop"
Set xlObj = CreateObject("Excel.Applic
'import the excel file
For j = LBound(filArr) To UBound(filArr)
xlObj.Workbooks.Open xlPath & "\" & filArr(j)
shtName = xlObj.Worksheets(1).Name
If filArr(j) = "Stock_Status_Report.xls" Then
DoCmd.RunSQL "DELETE * FROM " & table1
DoCmd.TransferSpreadsheet acImport, , table1, xlPath & "\" & filArr(j), True, shtName & "!"
' ElseIf filArr(j) = "On_Hand_Value.xls" Then
' DoCmd.RunSQL "DELETE * FROM " & table2
' DoCmd.TransferSpreadsheet acImport, , table2, xlPath & "\" & filArr(j), True, shtName & "!"
End If
Next
For j = LBound(filArr) To UBound(filArr)
xlObj.Workbooks.Close
Set xlObj = Nothing
On Error Resume Next
Kill xlPath & "\" & filArr(j) 'Delete the Excel files
Next
xlObj.Workbooks.Close
Set xlObj = Nothing
TerminateExcelProcess
'x_DropStockImportErrorsTa
'Add_Current_Date_Time
DoCmd.SetWarnings True
MsgBox "Stock data import complete."
End Sub
Sub Excel_Rename_Columns()
Dim xlObj As Excel.Application
Dim xlPath As String, shtName As String
Dim filArr(), j
Dim i As Integer
DoCmd.SetWarnings False
filArr = Array("Stock_Status_Report
xlPath = "C:\Users\sanjayg\Desktop"
Set xlObj = CreateObject("Excel.Applic
For j = LBound(filArr) To UBound(filArr)
xlObj.Workbooks.Open xlPath & "\" & filArr(j)
shtName = xlObj.Worksheets(1).Name
For i = 1 To xlObj.Worksheets(shtName).
If xlObj.Worksheets(shtName).
xlObj.Worksheets(shtName).
ElseIf xlObj.Worksheets(shtName).
xlObj.Worksheets(shtName).
ElseIf xlObj.Worksheets(shtName).
xlObj.Worksheets(shtName).
End If
Next
xlObj.Worksheets(shtName).
Next
xlObj.ActiveWorkbook.Save
'xlObj.Workbooks.Close
Set xlObj = Nothing
TerminateExcelProcess
'DoCmd.SetWarnings True
End Sub
I would assume this is because of the format of the Dates in the Excel sheet.
Try moving the data into a local Access table first, and then see what that column looks like.
In general, it's better to import to a local Access table first, and then use standard SQL to move the data over to SQL Server. This allows you to have much more control over the import, and allows you to detect problems with the data before it gets to the live tables.
Try moving the data into a local Access table first, and then see what that column looks like.
In general, it's better to import to a local Access table first, and then use standard SQL to move the data over to SQL Server. This allows you to have much more control over the import, and allows you to detect problems with the data before it gets to the live tables.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http:#39607364 is not a valid response - shouldn't that be https://www.experts-exchange.com/questions/28265810/a-column-is-not-importing-date-data-into-a-linked-sql-table.html?anchorAnswerId=39569397#a39569397
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
ASKER
Sub Excel_Rename_Columns()
Dim xlObj As Excel.Application
Dim xlPath As String, shtName As String
Dim filArr(), j
Dim i As Integer
DoCmd.SetWarnings False
filArr = Array("Stock_Status_Report
xlPath = "C:\Users\sanjayg\Desktop"
Set xlObj = CreateObject("Excel.Applic
For j = LBound(filArr) To UBound(filArr)
xlObj.Application.DisplayA
xlObj.Workbooks.Open xlPath & "\" & filArr(j)
xlObj.ActiveWorkbook.SaveA
Next
Set xlObj = Nothing
TerminateExcelProcess
filArr = Array("Stock_Status_Report
xlPath = "C:\Users\sanjayg\Desktop"
Set xlObj = CreateObject("Excel.Applic
For j = LBound(filArr) To UBound(filArr)
xlObj.Workbooks.Open xlPath & "\" & filArr(j)
shtName = xlObj.Worksheets(1).Name
For i = 1 To xlObj.Worksheets(shtName).
If xlObj.Worksheets(shtName).
xlObj.Worksheets(shtName).
ElseIf xlObj.Worksheets(shtName).
xlObj.Worksheets(shtName).
ElseIf xlObj.Worksheets(shtName).
xlObj.Worksheets(shtName).
End If
Next
xlObj.Worksheets(shtName).
Next
xlObj.ActiveWorkbook.Save
'xlObj.ActiveWorkbook.Save
'xlObj.Workbooks.Close
Set xlObj = Nothing
TerminateExcelProcess
'DoCmd.SetWarnings True
End Sub