Trouble with "On Error Goto"

Mmccl

Enough to be Scary
Local time
Yesterday, 18:11
Joined
Nov 26, 2003
Messages
43
Greetings,

I am a light weight database designer and vba code writer. I need some help.

I have a form with a delete button. Every time I click the Delete button, I need the form to warn me before deleting the record from the table or related tables.

Currently, when I click the delete button, it deletes the record with no warning.

Here is my code:

______________________________
Private Sub Delete_Click()
On Error GoTo Err_Delete_Click


DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

Exit_Delete_Click:
Exit Sub

Err_Delete_Click:
MsgBox Err.Description
Resume Exit_Delete_Click

End Sub
________________________________
Private Sub Form_Current()
' ok here is the problem code
' when I delete this code, I get the prompt before
' deleting a record

On Error GoTo Current_Err

If GrandTotal > "0" Then
Gift_toDate = GrandTotal

End If

If (OptionGroup.Value = True) Then
ChurchorIndividualText = "Church"


ElseIf (OptionGroup.Value = False) Then
ChurchorIndividualText = "Individual"

End If

Current_End:
Exit Sub

Current_Err:
MsgBox Err.Description
Resume Current_End


End Sub
_______________________________

I have tried removing different pieces of it, (ie. breaking it down) and nothing helps. But I need all these parts for the form to work correctly.

If I remove the secound private sub completely, the delete sub gives me no trouble.

Any help on how to re-write the 2nd part of this code so that the form will alert me before deleting a record would be helpful. I am totallly stumped here.

thanks
mike
 
Mike,

Good news (maybe): I don't think your second sub has anything to do with your problem.

Try something like this in the Delete_Click sub:

Code:
Private Sub Delete_Click()
On Error GoTo Err_Delete_Click

Dim Answer as vbMsgBoxResult

Answer = Msgbox("Are you sure you want to delete this thing?", vbYesNo, _
		"Confirm Delete")

	If Answer = VbYes Then
		    DoCmd.RunCommand acCmdDeleteRecord
	End if

Exit_Delete_Click:
Exit Sub

Err_Delete_Click:
MsgBox Err.Description
Resume Exit_Delete_Click

End Sub

Regards,
Tim
 
Mmccl said:
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

These two lines are obsolete.

Replace them with:

Code:
DoCmd.RunCommand acCmdDeleteRecord
 
I think you need both commands Mile.

The code generated by the Wizards is in a time warp and is left over from A95. Microsoft suggests that you do not use these methods but it hasn't bothered to clean its own house. Replace the DoMenuItem's with the following:

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord
 

Users who are viewing this thread

Back
Top Bottom