VBA: OpenRecordset .AddNew method runs slow

前端 未结 1 747
挽巷
挽巷 2021-01-25 15:03

I have an Access application which has a table (AuditTrail) linked to SQL Server 2008. I am trying to add records to the audit trail table programmatically.

I have the f

相关标签:
1条回答
  • 2021-01-25 15:33

    With your current code, you are opening the entire table for no reason. There are a couple of options.
    One is to add a where clause that will return no records. Something like
    Select dtDateTime, txtComment FROM AuditTrail WHERE <yourIdField> = -1.

    The second (my preference) would be to not use a recordset at all. Use an insert statement.

    Dim strSql as String strSql = "INSERT INTO AuditTrail (dtDateTime, txtComment) Values(#" & Noe() & "#,'" & nz(MyComment,'') & "')" 
    Db.Execute strSql, dbFailOnerror + DbSeeChanges`
    
    0 讨论(0)
提交回复
热议问题