I am currently trying to write a script that will take a table out of excel and place it into access automatically, by a press of a button. So far everything works except when I try to send data to my Date Field and my Time Field. I have these both set in excel as text and in access as text as well. my field names in access are Date and Time. Here is my script any and all help would be grateful
Sub Inserting()
Dim rs As Recordset
Set rs = New Recordset
Dim n As Date
Dim ID As String
Dim Genpart As String
Dim Amount As Integer
Dim Location As String
Dim Datea As String
Dim Timea As String
Dim Typea As String
Count = 1
While Worksheets("sheet1").Range("a" & Count) <> ""
ID = Worksheets("sheet1").Range("a" & Count)
Genpart = Worksheets("sheet1").Range("b" & Count)
Amount = Worksheets("sheet1").Range("c" & Count)
Location = Worksheets("sheet1").Range("d" & Count)
Datea = Worksheets("sheet1").Range("e" & Count)
Timea = Worksheets("sheet1").Range("f" & Count)
Typea = Worksheets("sheet1").Range("g" & Count)
'This is my main strsql string
'strSQL = "INSERT INTO Cyclecount (Id, Genpart, Amount, Location, Date, Time, Type) VALUES (" & "'" & ID & "'," & "'" & Genpart & "'," & Amount & "," & "'" & Location & "'," & "'" & Datea & "'," & "'" & Timea & "'" & ", '" & Typea & "'" & ");"
'This is my test strsql string
strSQL = "INSERT INTO cyclecount (Date) VALUES (" & "'" & Datea & "');"
'all this does is send it to my spread sheet to show what I am trying to say in sql
e = "INSERT INTO cyclecount (Date) VALUES (" & "'" & Datea & "');"
Range("i1") = e
'Adjust Filepath to Access in this string as needed
Const strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & _
"L:\Manufacturing\JWallace\cyclecount\Cyclecount.mdb" & _
";Persist Security Info=False"
Call rs.Open(strSQL, strConnectionString)
'rs.MoveFirst 'Header
'rs.MoveNext 'Actual first record
If (rs.State And ObjectStateEnum.adStateOpen) Then rs.Close
If Not rs Is Nothing Then Set rs = Nothing
Count = Count + 1
Wend
End Sub
Sub Inserting()
Dim rs As Recordset
Set rs = New Recordset
Dim n As Date
Dim ID As String
Dim Genpart As String
Dim Amount As Integer
Dim Location As String
Dim Datea As String
Dim Timea As String
Dim Typea As String
Count = 1
While Worksheets("sheet1").Range("a" & Count) <> ""
ID = Worksheets("sheet1").Range("a" & Count)
Genpart = Worksheets("sheet1").Range("b" & Count)
Amount = Worksheets("sheet1").Range("c" & Count)
Location = Worksheets("sheet1").Range("d" & Count)
Datea = Worksheets("sheet1").Range("e" & Count)
Timea = Worksheets("sheet1").Range("f" & Count)
Typea = Worksheets("sheet1").Range("g" & Count)
'This is my main strsql string
'strSQL = "INSERT INTO Cyclecount (Id, Genpart, Amount, Location, Date, Time, Type) VALUES (" & "'" & ID & "'," & "'" & Genpart & "'," & Amount & "," & "'" & Location & "'," & "'" & Datea & "'," & "'" & Timea & "'" & ", '" & Typea & "'" & ");"
'This is my test strsql string
strSQL = "INSERT INTO cyclecount (Date) VALUES (" & "'" & Datea & "');"
'all this does is send it to my spread sheet to show what I am trying to say in sql
e = "INSERT INTO cyclecount (Date) VALUES (" & "'" & Datea & "');"
Range("i1") = e
'Adjust Filepath to Access in this string as needed
Const strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & _
"L:\Manufacturing\JWallace\cyclecount\Cyclecount.mdb" & _
";Persist Security Info=False"
Call rs.Open(strSQL, strConnectionString)
'rs.MoveFirst 'Header
'rs.MoveNext 'Actual first record
If (rs.State And ObjectStateEnum.adStateOpen) Then rs.Close
If Not rs Is Nothing Then Set rs = Nothing
Count = Count + 1
Wend
End Sub