By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,495 Members | 1,329 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,495 IT Pros & Developers. It's quick & easy.

Replace Standard Error Messages

P: n/a
Bob
Hi Everybody

I hope you can help.

2 related questions.

1. I am looking for a way to replace the confusing message box that comes up when a user trys to
open a form without putting data in it.
ie ..Syntax Error(Missing Operator) In queryexpression '[WriteID="
which seems to puzzle users

I would like to replace that with something more user friendly.
The code I am currenly using is:

Private Sub txtRe_DblClick(Cancel As Integer)
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
On Error GoTo Err_txtRe_DblClick

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmSupplierWriteText"
stLinkCriteria = "[WriteID]=" & Me![WriteID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_txtRe_DblClick:
Exit Sub
Err_txtRe_DblClick:
MsgBox Err.Description
Resume Exit_txtRe_DblClick
End Sub
2. I would also like to replace the message "You are about to delete 1 record(s) If you click Yes
you won't be able to undo this operation. Are you sure you want to delete these records.

If the user says "No" then "The DoMenuItem was cancelled". Not very user friendly. I am looking to
replace this with something better. The code I am using at the moment is:

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

Grateful for any Help

Smiley Bob
Nov 12 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
The first error message occurs when WriteID is null. Because there is no
number at all, the link criteria string becomes just:
WriteID =
which is a nonsense that Access cannot understand. To avoid that, test for
Null before assigning the string:

If IsNull(Me.WriteID) Then
Beep
Else
stDocName = "frmSupplierWriteText"
stLinkCriteria = "[WriteID]=" & Me![WriteID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
The 2nd message is Access' way of notifying you (the programmer) that the
action you asked for did not happen. If you temporarily comment out the
error handler line ("On Error Goto..."), you will be able to see the message
number, and then just ignore that number in your error handler. This example
shows how to ignore Error 2501:

Err_delete_Click:
If Err.Number <> 2501 Then
MsgBox Err.Description
End If
Resume Exit_delete_Click
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Bob" <sm*******@hotmail.com> wrote in message
news:hn********************************@4ax.com...
Hi Everybody

I hope you can help.

2 related questions.

1. I am looking for a way to replace the confusing message box that comes up when a user trys to open a form without putting data in it.
ie ..Syntax Error(Missing Operator) In queryexpression '[WriteID="
which seems to puzzle users

I would like to replace that with something more user friendly.
The code I am currenly using is:

Private Sub txtRe_DblClick(Cancel As Integer)
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
On Error GoTo Err_txtRe_DblClick

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmSupplierWriteText"
stLinkCriteria = "[WriteID]=" & Me![WriteID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_txtRe_DblClick:
Exit Sub
Err_txtRe_DblClick:
MsgBox Err.Description
Resume Exit_txtRe_DblClick
End Sub
2. I would also like to replace the message "You are about to delete 1 record(s) If you click Yes you won't be able to undo this operation. Are you sure you want to delete these records.
If the user says "No" then "The DoMenuItem was cancelled". Not very user friendly. I am looking to replace this with something better. The code I am using at the moment is:

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

Grateful for any Help

Smiley Bob

Nov 12 '05 #2

P: n/a
Bob
On Mon, 26 Apr 2004 09:25:09 +0800, "Allen Browne" <Al*********@SeeSig.Invalid> wrote:

Thanks for that Allen. The First code works well. I now have my OWN message box that gives the user
The instuction "You MUST Enter a reference Title"

The 2nd one I don't think I explained myself correctly. What I am looking to achieve is to REPLACE
the message "You are about to delete 1 record(s) If you click Yes you won't be able to undo this
operation. Are you sure you want to delete these records. WITH a message box that says "Are your
sure you want to delete this Letter" and a Yes/No.

If the user selects Yes Message Box "Letter Deleted " and it deletes.
If the user selects No Message Box "Letter Not Deleted " and it remains

Thanks

Smiley Bob


Nov 12 '05 #3

P: n/a
Okay, Bob. Use the BeforeDelConfirm event of the form if you wish to pop up
your own message box. Example from the help file:

Private Sub Form_BeforeDelConfirm(Cancel As Integer, _
Response As Integer)
' Suppress default Delete Confirm dialog box.
Response = acDataErrContinue
' Display custom dialog box.
If MsgBox("Delete this record?", vbOKCancel) = vbCancel Then
Cancel = True
End If
End Sub

Please be aware, though, that the default message accurately notifies the
user about the number of records being deleted (since more than one can be
selected in a datasheet or continuous form), and if related records will be
deleted thorugh a cascading delete. These two issues are not exposed to you
for your custom message, and it could take quite a bit more code to achieve
that.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Bob" <sm*******@hotmail.com> wrote in message
news:lm********************************@4ax.com...
On Mon, 26 Apr 2004 09:25:09 +0800, "Allen Browne" <Al*********@SeeSig.Invalid> wrote:
Thanks for that Allen. The First code works well. I now have my OWN message box that gives the user The instuction "You MUST Enter a reference Title"

The 2nd one I don't think I explained myself correctly. What I am looking to achieve is to REPLACE the message "You are about to delete 1 record(s) If you click Yes you won't be able to undo this operation. Are you sure you want to delete these records. WITH a message box that says "Are your sure you want to delete this Letter" and a Yes/No.

If the user selects Yes Message Box "Letter Deleted " and it deletes.
If the user selects No Message Box "Letter Not Deleted " and it remains

Thanks

Smiley Bob

Nov 12 '05 #4

P: n/a
Bob wrote...
"Bob" <sm*******@hotmail.com> wrote in message
news:lm********************************@4ax.com...
On Mon, 26 Apr 2004 09:25:09 +0800, "Allen Browne" <Al*********@SeeSig.Invalid> wrote:
Thanks for that Allen. The First code works well. I now have my OWN message box that gives the user The instuction "You MUST Enter a reference Title"

The 2nd one I don't think I explained myself correctly. What I am looking to achieve is to REPLACE the message "You are about to delete 1 record(s) If you click Yes you won't be able to undo this operation. Are you sure you want to delete these records. WITH a message box that says "Are your sure you want to delete this Letter" and a Yes/No.

If the user selects Yes Message Box "Letter Deleted " and it deletes.
If the user selects No Message Box "Letter Not Deleted " and it remains

Thanks

Smiley Bob


Bob,

I use the following code on my Delete buttons "on Click Event Procedure: you
may wish to change the error handling to reflect your own.
Hope this help's

Cheers,

Dave

' ---------- Code Starts ----------
Private Sub cmdDeleteRecord_Click()
' Button: Delete Record
On Error GoTo ErrorHandler
DoCmd.SetWarnings False

If MsgBox("You are about to delete the current record" & Chr(13) & " " &
_
Chr(13) & "If you select 'Yes' you will not be able to UNDO this
action;" _
& Chr(13) & " " & Chr(13) & "it will be immediate and irreversible!" _
& Chr(13) & " " & Chr(13) & "Do you wish to continue?", vbQuestion + _
vbYesNo + vbDefaultButton2, "Delete?") = vbYes Then
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord
Me!cboFind.Requery
End If

ExitProcedure:
Exit Sub
ErrorHandler:

If Err = 2046 Then 'Command not available
MsgBox "No Record to Delete, canceling delete action."
ElseIf Err = 2501 Then ' Action was cancelled
Resume Next
Resume ExitProcedure
Else

Select Case Err.Number
Case Else ' Any unexpected error.
Call LogError(Err.Number, Err.Description,
"cmdDeleteRecord_Click()")
End Select

End If

End Sub
' ---------- Code Ends ----------
Nov 12 '05 #5

P: n/a
Bob
On Mon, 26 Apr 2004 14:50:59 GMT, "Dave Brydon" <db*****@ns.sympatico.ca> wrote:

Thanks Guys! Both of those worked well.

I love this NG

Bob
Bob wrote...
"Bob" <sm*******@hotmail.com> wrote in message
news:lm********************************@4ax.com.. .
On Mon, 26 Apr 2004 09:25:09 +0800, "Allen Browne"

<Al*********@SeeSig.Invalid> wrote:

Thanks for that Allen. The First code works well. I now have my OWN

message box that gives the user
The instuction "You MUST Enter a reference Title"

The 2nd one I don't think I explained myself correctly. What I am looking

to achieve is to REPLACE
the message "You are about to delete 1 record(s) If you click Yes you

won't be able to undo this
operation. Are you sure you want to delete these records. WITH a message

box that says "Are your
sure you want to delete this Letter" and a Yes/No.

If the user selects Yes Message Box "Letter Deleted " and it deletes.
If the user selects No Message Box "Letter Not Deleted " and it remains

Thanks

Smiley Bob


Bob,

I use the following code on my Delete buttons "on Click Event Procedure: you
may wish to change the error handling to reflect your own.
Hope this help's

Cheers,

Dave

' ---------- Code Starts ----------
Private Sub cmdDeleteRecord_Click()
' Button: Delete Record
On Error GoTo ErrorHandler
DoCmd.SetWarnings False

If MsgBox("You are about to delete the current record" & Chr(13) & " " &
_
Chr(13) & "If you select 'Yes' you will not be able to UNDO this
action;" _
& Chr(13) & " " & Chr(13) & "it will be immediate and irreversible!" _
& Chr(13) & " " & Chr(13) & "Do you wish to continue?", vbQuestion + _
vbYesNo + vbDefaultButton2, "Delete?") = vbYes Then
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord
Me!cboFind.Requery
End If

ExitProcedure:
Exit Sub
ErrorHandler:

If Err = 2046 Then 'Command not available
MsgBox "No Record to Delete, canceling delete action."
ElseIf Err = 2501 Then ' Action was cancelled
Resume Next
Resume ExitProcedure
Else

Select Case Err.Number
Case Else ' Any unexpected error.
Call LogError(Err.Number, Err.Description,
"cmdDeleteRecord_Click()")
End Select

End If

End Sub
' ---------- Code Ends ----------


Nov 12 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.