Newbie question about bypassing Access messages

T

tina

SetWarnings is already turned off when the record is deleted, so my guess is
that the system is showing that message because of the subsequent (and
unnecessary) line
Resume Exit_btnDeleteRecord_Click

try this:

Private Sub btnDeleteRecord_Click()
On Error GoTo Err_btnDeleteRecord_Click

DoCmd.Beep
If vbYes = MsgBox("Are you sure you want to delete the product?",
vbCritical + vbYesNo, "Product Deletion") Then
DoCmd.SetWarnings False
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
Else
MsgBox "The product is still in the list", , "Delete action
canceled"
End If

Exit_btnDeleteRecord_Click:
DoCmd.SetWarnings True
Exit Sub

Err_btnDeleteRecord_Click:
MsgBox Err.Number & " " & Err.Description
Resume Exit_btnDeleteRecord_Click

End Sub

if you're using an error handler in a procedure that turns off Warnings,
it's a good idea to make sure the handler turns *on* Warnings before exiting
the procedure. also, if an unanticipated error triggers the handler, it
helps to see the error number, as well as the description, for trapping
purposes.

btw, in A2000 or newer, you can replace the two DoMenuItem lines with a
single line
DoCmd.RunCommand acCmdDeleteRecord
it may work in A97 as well, but i'm afraid that i can't remember.

hth
 
A

Amir

Hi!

I have a command button for deleting records from a products list.
When the user presses the button, Access asks if he is sure he
want's to delete the product, and if he presses "Yes", then it deletes
the product record, and then shows a message saying:
"Resume without error", and the user has the press the "OK"
button, in order to continue.


How can I Disable the "Resume without error" message,
so that the user won't have to click anything after the product is deleted?

Here is the code:

Private Sub btnDeleteRecord_Click()
On Error GoTo Err_btnDeleteRecord_Click

DoCmd.Beep
If vbYes = MsgBox("Are you sure you want to delete the product?",
vbCritical + vbYesNo, "Product Deletion") Then
DoCmd.SetWarnings False
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
DoCmd.SetWarnings True
Resume Exit_btnDeleteRecord_Click
Else
MsgBox "The product is still in the list", , "Delete action
canceled"
End If

Exit_btnDeleteRecord_Click:
Exit Sub

Err_btnDeleteRecord_Click:
MsgBox Err.Description
Resume Exit_btnDeleteRecord_Click

End Sub


Thank you very much for your help!
 
A

Amir

Thank you very much tina!

Now I don't see the "Resume without error" message, however
I get a message saying: "No current record".

Can I disable this message too?
 
T

tina

suggest you step through the code, to see what line is triggering that
message. then post the entire procedure, and indicate which line.
 
A

Amir

OK, At the "MsgBox Err.Description" Line
I get a message saying that the command
or the action "Select Record" are not available now.

I can get rid of the error message by deleting this line,
but I still don't understand the meaning of this message.
 
T

tina

that's not the line that's triggering the error, it's the error message.
step through it again, and see what line is highlighted immediately *before*
the highlight jumps to line
Err_btnDeleteRecord_Click:

and please post the procedure, as i requested before. i want to see what it
looks like since you made a change from the code posted originally.
 
A

Amir

OK, I didn't know that.. :)

The line which makes the error is the second line of the DoMenuItem.
(DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70)

Here is the code:

Private Sub btnDeleteRecord_Click()
On Error GoTo Err_btnDeleteRecord_Click

DoCmd.Beep
If vbYes = MsgBox("Are you sure you want to delete the
product?", vbCritical + vbYesNo, "Product Deletion") Then
DoCmd.SetWarnings False
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
Else
MsgBox "The product is still in the list", , "Delete action
canceled"
End If

Exit_btnDeleteRecord_Click:
DoCmd.SetWarnings True
Exit Sub

Err_btnDeleteRecord_Click:
MsgBox Err.Description
Resume Exit_btnDeleteRecord_Click

End Sub
 
T

tina

suggest you remove *both* DoMenuItem lines of code, and replace with

DoCmd.RunCommand acCmdDeleteRecord

hth
 
A

Amir

Hi,
It didn't help, but I've noticed a new thing:
I only get the error message if I am deleting the *last*
record in the list. If I delete a record which isn't last,
I don't get the error message. Any ideas?
 
T

tina

a simple delete of a current record should not cause that error, unless you
are entering a new record and then trying to delete it *before* it is saved
to the table - that might cause such an error.
however: if you are using the single DoCmd line that i gave you, and it is
deleting the correct record and ONLY that record, and nothing else is
happening to your data that you *don't* want to happen, then i would just
trap that error.
make sure the Msgbox line is still in your error handler, and include the
Err.Number in the message as i posted previously. run the code again, and
this time write down the error number that shows in the message box. then
change your error handler as follow:

Err_btnDeleteRecord_Click:
Select Case Err.Number
Case (type in the number you wrote down, *without* the parenthesis)
Resume Exit_btnDeleteRecord_Click
Case Else
MsgBox Err.Number & " " & Err.Description
Resume Exit_btnDeleteRecord_Click
End Select

if you have any problem with this, then post your entire current procedure
again. i'll need to see it in its' current state, to fix it.
 
A

Amir

OK, I've done that. It seems that there are no unwanted results to my data.

Thank you very much!!
 

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

Similar Threads

DLookUp Not Working 3
Find button not working on Subform 1
Duplicate record question again with code? 3
Copy Record 3
Access 2002 SP3 4
Delete record error 3
Good Programming Practices???? 1
navigator buttons 6

Top