I am trying to upload all the columns in excel sheet to msaccess using sql with adodb. Everything works fine except the date columns where some of the rows will have blanks. Suppose If i wanted to upload 5 rows to ms access from excel sheet and any of the date column is blank in the first row, then its throwing me an data type mismatch error. but if i sort the date column in excel by rows with dates being top and blanks being bottom and if i try to upload, it uploads fine.
So my concern is ms access considering the column datatype based on the first row value in excel, even though i declared as proper data type in ms access.
Here is the code i am using
Public Sub Upload_Data_from_excel()
Set cn = CreateObject("ADODB.Connection")
dbPath = ThisWorkbook.Path & "\db.accdb"
dbWb = ThisWorkbook.FullName
dbWs_shtname = "SHEET1"
tbl_name = "TBL_EXCEL_DATA"
scn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & dbPath & ";Jet OLEDB:Database Password=123456"
cn.Open scn
' Delete existing records
ssql = "DELETE * FROM " & tbl_name
cn.Execute ssql
dsh = "[" & dbWs_shtname & "$]"
ssql = "INSERT INTO " & tbl_name & " "
ssql = ssql & "SELECT * FROM [Excel 8.0;HDR=YES;DATABASE=" & dbWb & "]." & dsh
cn.Execute ssql
Set cn = Nothing
Application.StatusBar = ""
End Sub
any support is much appreciated


NAME2is blank in both your "working" *and your "non-working" examples, and neither has the "blanks being bottom". Also, what does "not working" mean -- on which line of code do you get the error? Please see "minimal reproducible example".