How to insert values into the database table using VBA in MS access

后端 未结 3 742
自闭症患者
自闭症患者 2020-12-18 07:37

I\'ve started to use access recently. I am trying to insert a few rows into the database; however, I am stuck as it is throwing an error:

Too few par

3条回答
  •  爱一瞬间的悲伤
    2020-12-18 08:09

    since you mentioned you are quite new to access, i had to invite you to first remove the errors in the code (the incomplete for loop and the SQL statement). Otherwise, you surely need the for loop to insert dates in a certain range.

    Now, please use the code below to insert the date values into your table. I have tested the code and it works. You can try it too. After that, add your for loop to suit your scenario

    Dim StrSQL As String
    Dim InDate As Date
    Dim DatDiff As Integer
    
    InDate = Me.FromDateTxt
    
    StrSQL = "INSERT INTO Test (Start_Date) VALUES ('" & InDate & "' );"
    
    DoCmd.SetWarnings False
    DoCmd.RunSQL StrSQL
    DoCmd.SetWarnings True
    

提交回复
热议问题