Delete records without messagebox

  • Thread starter jubiiab via AccessMonster.com
  • Start date
J

jubiiab via AccessMonster.com

Hi

I have a button on my form that execute some code and commands. One of the
cmd in that button is:

DoCmd.RunSQL "DELETE tbl_ValueRelation.* FROM tbl_ValueRelation"

it works but everytime the cmd is executed I get a messagebox where it ask me
if I want to delete these records. Can I some how make it to not show this
message and just do the delete cmd??

I hope you understand what I wrote. My english is not so good.
 
A

Allen Browne

SetWarnings will suppress the confirmation message, but then you won't know
if the deletion worked completely or not.

A better solution would be to use the Execute method instead of RunSQL.
Details in:
Action queries: suppressing dialogs, while knowing results
at:
http://allenbrowne.com/ser-60.html
 
J

jubiiab via AccessMonster.com

Hi Allen!

Thx for your replay.

I have looked at your site but I am not sure how to write the code in the
button. I tried to add this:

Dim db As DAO.Database
Dim strSql As String

strSql = "DELETE * FROM tbl_ValueRelation"
Set db = DBEngine(0)(0)
db.Execute strSql, dbFailOnError
'MsgBox db.RecordsAffected & " record(s) were unpicked."
Set db = Nothing


but its not working :(

Allen said:
SetWarnings will suppress the confirmation message, but then you won't know
if the deletion worked completely or not.

A better solution would be to use the Execute method instead of RunSQL.
Details in:
Action queries: suppressing dialogs, while knowing results
at:
http://allenbrowne.com/ser-60.html
[quoted text clipped - 9 lines]
I hope you understand what I wrote. My english is not so good.
 
A

Allen Browne

I assume you set your command button's On Click property to:
[Event Procedure]

Then you clicked the Build button (...) beside this property.
Access opened the code window.
You put the code in there.

When you say, "not working" -- what's happening? Anything? Nothing? Error?

Remove the single quote at the start of the MsgBox line, so you see the
message.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


jubiiab via AccessMonster.com said:
Hi Allen!

Thx for your replay.

I have looked at your site but I am not sure how to write the code in the
button. I tried to add this:

Dim db As DAO.Database
Dim strSql As String

strSql = "DELETE * FROM tbl_ValueRelation"
Set db = DBEngine(0)(0)
db.Execute strSql, dbFailOnError
'MsgBox db.RecordsAffected & " record(s) were unpicked."
Set db = Nothing


but its not working :(

Allen said:
SetWarnings will suppress the confirmation message, but then you won't
know
if the deletion worked completely or not.

A better solution would be to use the Execute method instead of RunSQL.
Details in:
Action queries: suppressing dialogs, while knowing results
at:
http://allenbrowne.com/ser-60.html
[quoted text clipped - 9 lines]
I hope you understand what I wrote. My english is not so good.
 

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