ignore warnings

K

Katrina

I have a delete query running through code that creates a
message box and then if the user says "Ok" the delete
query is run...

Access is asking if I'm sure I want to delete x records.

I would like to ignore this, or automatically say "yes"
since I have a seperate precaution in place... any help?

I am running the delete query through DoCmd.RunSql

Thanks
 
J

Jean-Francois Bouthilleir

I would suggest adding the lines:

DoCmd.SetWarnings (False) -> (before the query is ran)

and

DoCmd.SetWarnings (True) -> (after is is ran)

I would also make sure that in case of an error, I would
also set warnings back to True.

HTH.
 
T

Tim Ferguson

I have a delete query running through code that creates a
message box and then if the user says "Ok" the delete
query is run...

Use db.Execute rather than DoCmd.RunSQL


Faster, better control (check the dbFailOnError parameter) and you can't
forget to switch SetWarnings back on again.


HTH


Tim F
 
G

Guest

I don't know how to used db.execute

Can you please include a few more lines of code to show me
how I would use this?

Do I have call out db as something... what are the rest of
the arguements for execute?

Thanks
 
T

Tim Ferguson

I don't know how to used db.execute

Can you please include a few more lines of code to show me
how I would use this?

Have you looked at the help files? It's fairly well explained.

Dim db As DAO.Database
Dim strSQL As String

' Some kind of SQL command
strSQL = "INSERT INTO People (FName, LName, Phone) " & _
"VALUES (""Eric"", ""Lafayette"", ""09887 234-123"")"

' Create a handle to the database. Not strictly necessary, but
' improves readability and future-proofing
Set db = CurrentDB()

' Get ready to execute the command. We don't want the user to see if
' there is an error returned
On Error Resume Next

' Now execute the command. The only choice for the second parameter
' is dbFailOnError, which makes an Error if the SQL could not run.
' If you don't put it in, then the SQL will simply fail without
' letting anybody know.
db.Execute strSQL, dbFailOnError

' Did it go okay?
If Err.Number <> 0 Then
' No: oh dear. Do something useful here

Else
' Okay, it was alright. Do something else useful here

End If

' Restore error handling
On Error GoTo 0

' and carry on with the rest of process...


Hope that helps


Tim F
 
G

Guest

Thanks so much
-----Original Message-----


Have you looked at the help files? It's fairly well explained.

Dim db As DAO.Database
Dim strSQL As String

' Some kind of SQL command
strSQL = "INSERT INTO People (FName, LName, Phone) " & _
"VALUES (""Eric"", ""Lafayette"", ""09887 234-123"")"

' Create a handle to the database. Not strictly necessary, but
' improves readability and future-proofing
Set db = CurrentDB()

' Get ready to execute the command. We don't want the user to see if
' there is an error returned
On Error Resume Next

' Now execute the command. The only choice for the second parameter
' is dbFailOnError, which makes an Error if the SQL could not run.
' If you don't put it in, then the SQL will simply fail without
' letting anybody know.
db.Execute strSQL, dbFailOnError

' Did it go okay?
If Err.Number <> 0 Then
' No: oh dear. Do something useful here

Else
' Okay, it was alright. Do something else useful here

End If

' Restore error handling
On Error GoTo 0

' and carry on with the rest of process...


Hope that helps


Tim F

.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top