Hier erhalte ich Fehler beiTypenkonflikt Laufzeitfehler-13 in VBA (zeigt Fehler bei Datum Variable)
Dim strDate As Date
als Typenkonflikt Laufzeitfehler ..
Bitte jede Hilfe dankbar sein ....
Sub Insert11()
'click on tools and select Microsoft ActiveX data Objects 2.0 Library
Dim DBFullName As String
Dim Connect As String, Source As String
Dim Connection As ADODB.Connection
Dim Recordset As ADODB.Recordset
Dim Col As Integer
Dim strDate As Date
Dim strWeight As Variant
Dim strMed_Id As Variant
Dim strGlucose As Variant
strDate = InsertForm.TextBox1.Value
strWeight = InsertForm.TextBox2.Value
strMed_Id = InsertForm.ListBox2.Value
strGlucose = InsertForm.TextBox3.Value
' InsertForm.Show
Cells.Clear
'Database path info
DBFullName = "C:\Users\ND5036832\Downloads\Assignment1234\Sample1.accdb"
'open the connection
Set Connection = New ADODB.Connection
Connect = "Provider=Microsoft.ACE.OLEDB.12.0;"
Connect = Connect & "Data Source=" & DBFullName & ";"
Connection.Open ConnectionString:=Connect
'Create RecordSet
Set Recordset = New ADODB.Recordset
With Recordset
'filter Data
Source = "Insert into Glucose ([Date],Weight, Med_Id,Glucose) values (" & strDate & "," & strWeight & "," & strMed_Id & "," & strGlucose & ");"
.Open Source:=Source, ActiveConnection:=Connection
'Msgbox " The query:" & vbNewLine & vbNewLine & Source
'Write field names
For Col = 0 To Recordset.Fields.Count - 1
Range("G1").Offset(0, Col).Value = Recordset.Fields(Col).Name
Next
'Write recordset
'Range("G1").Offset(1, 0).CopyFromRecordset Recordset
End With
ActiveSheet.Columns.AutoFit
Set Recordset = Nothing
Connection.Close
Set Connection = Nothing
End Sub
'Dim strDate As Date' sollte keinen Fehler werfen. Aktualisieren Sie Ihre Frage bitte mit dem echten Fehler. –
Danke @ Robin Mackenzie Hier die erste Zeile selbst sagt Dim strDate als Datum zeigt typeMismatch Laufzeitfehler-13 –