How to insert ADO Recordset into MS Access Table

后端 未结 2 608
渐次进展
渐次进展 2020-12-31 18:00

PROBLEM

I want to insert the current recordset row into a MS Access table. I am currently getting this error

Syntax error (missing o         


        
相关标签:
2条回答
  • 2020-12-31 18:42

    Open tblSummary_Appl_Usage_score as a DAO recordset. Then use its .AddNew method to create a new row and store the values from your ADO recordset.

    Dim db As DAO.database
    Dim rsDao As DAO.Recordset
    Set db = CurrentDb
    Set rsDao = db.OpenRecordset("tblSummary_Appl_Usage_score", dbOpenTable, dbAppendOnly)
    rsDao.AddNew
    rsDao![Configuration] = rs![Configuration]
    rsDao![User Input / Output] = rs![User Input / Output]
    rsDao.Update
    

    With this approach, your code needn't be adapted differently based on the recordset field data types. It will work correctly regardless of data type as long as the matching fields are both the same or compatible data types.

    0 讨论(0)
  • 2020-12-31 18:54

    If the type fields in your table tblSummary_Appl_Usage_score are numbers, use this:

    DoCmd.RunSQL "INSERT INTO tblSummary_Appl_Usage_score VALUES (" & rs![Configuration] & "," & rs![User Input / Output] & ")"
    

    If the type is string, use this:

    DoCmd.RunSQL "INSERT INTO tblSummary_Appl_Usage_score VALUES (""" & rs![Configuration] & """,""" & rs![User Input / Output] & """)"
    
    0 讨论(0)
提交回复
热议问题