/ Published in: Visual Basic
Running queries in Access to ignore warnings and get affected record count
- 'Using Execute instead of DoCmd.RunSQL suppresses the warning dialogs
- 'automatically without having to mess with turning DoCmd.SetWarnings
- 'off and then back on when finished (if you remember).
- 'Execute can be used to run a query string you construct, or an Access
- 'stored query.
- Dim strSql As String
- strSql = "UPDATE table SET field = newvalue WHERE field = currentvalue"
- CurrentDb.Execute (strSql), dbFailOnError
- 'The parameter "dbFailOnError" terminates the execute command if the,
- 'query fails, so I use it pretty much always.
- 'Also, when running this, you can return the number of rows affected
- Dim intRowsAffected As Integer
- intRowsAffected = CurrentDb.RecordsAffected
- 'If for some reason you are expecting lots of errors, you may want to
- 'stick with DoCmd.RunSQL and leave DoCmd.SetWarnings = true. I don't
- 'like this as it always presents the user with "You are about to
- 'update a bunch of records, are you sure" or something similar
- 'depending on the operation you are running.
You need to login to post a comment.