を(日付変数にエラーを示す)私は、型の不一致実行時エラーとして日型の不一致実行時エラー-13 VBAでここ
として
薄暗いstrDateでエラーを取得しています。..
任意の助けが理解されるだろうしてください....
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」はエラーを送出しません。あなたの質問を実際のエラーで更新してください。 –
ありがとうございました@ Robin MackenzieここでDimStrDateと表示されている日付はtypeMismatchランタイムエラー-13を示す日付です –