473,665 Members | 2,740 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Replace Standard Error Messages

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.DoMenuIte m acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
On Error GoTo Err_txtRe_DblCl ick

Dim stDocName As String
Dim stLinkCriteria As String

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

Exit_txtRe_DblC lick:
Exit Sub
Err_txtRe_DblCl ick:
MsgBox Err.Description
Resume Exit_txtRe_DblC lick
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_Clic k
DoCmd.DoMenuIte m acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuIte m acFormBar, acEditMenu, 6, , acMenuVer70
Exit_delete_Cli ck:
Exit Sub
Err_delete_Clic k:
MsgBox Err.Description
Resume Exit_delete_Cli ck
End Sub

Grateful for any Help

Smiley Bob
Nov 12 '05 #1
5 5053
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.Write ID) Then
Beep
Else
stDocName = "frmSupplierWri teText"
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_Clic k:
If Err.Number <> 2501 Then
MsgBox Err.Description
End If
Resume Exit_delete_Cli ck
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*******@hotm ail.com> wrote in message
news:hn******** *************** *********@4ax.c om...
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.DoMenuIte m acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
On Error GoTo Err_txtRe_DblCl ick

Dim stDocName As String
Dim stLinkCriteria As String

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

Exit_txtRe_DblC lick:
Exit Sub
Err_txtRe_DblCl ick:
MsgBox Err.Description
Resume Exit_txtRe_DblC lick
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_Clic k
DoCmd.DoMenuIte m acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuIte m acFormBar, acEditMenu, 6, , acMenuVer70
Exit_delete_Cli ck:
Exit Sub
Err_delete_Clic k:
MsgBox Err.Description
Resume Exit_delete_Cli ck
End Sub

Grateful for any Help

Smiley Bob

Nov 12 '05 #2
Bob
On Mon, 26 Apr 2004 09:25:09 +0800, "Allen Browne" <Al*********@Se eSig.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
Okay, Bob. Use the BeforeDelConfir m event of the form if you wish to pop up
your own message box. Example from the help file:

Private Sub Form_BeforeDelC onfirm(Cancel As Integer, _
Response As Integer)
' Suppress default Delete Confirm dialog box.
Response = acDataErrContin ue
' 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*******@hotm ail.com> wrote in message
news:lm******** *************** *********@4ax.c om...
On Mon, 26 Apr 2004 09:25:09 +0800, "Allen Browne" <Al*********@Se eSig.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
Bob wrote...
"Bob" <sm*******@hotm ail.com> wrote in message
news:lm******** *************** *********@4ax.c om...
On Mon, 26 Apr 2004 09:25:09 +0800, "Allen Browne" <Al*********@Se eSig.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.SetWarnin gs 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 + vbDefaultButton 2, "Delete?") = vbYes Then
DoCmd.RunComman d acCmdSelectReco rd
DoCmd.RunComman d acCmdDeleteReco rd
Me!cboFind.Requ ery
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.Nu mber, Err.Description ,
"cmdDeleteRecor d_Click()")
End Select

End If

End Sub
' ---------- Code Ends ----------
Nov 12 '05 #5
Bob
On Mon, 26 Apr 2004 14:50:59 GMT, "Dave Brydon" <db*****@ns.sym patico.ca> wrote:

Thanks Guys! Both of those worked well.

I love this NG

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

<Al*********@S eeSig.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.SetWarnin gs 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 + vbDefaultButton 2, "Delete?") = vbYes Then
DoCmd.RunComman d acCmdSelectReco rd
DoCmd.RunComman d acCmdDeleteReco rd
Me!cboFind.Requ ery
End If

ExitProcedur e:
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.Nu mber, Err.Description ,
"cmdDeleteReco rd_Click()")
End Select

End If

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


Nov 12 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
3129
by: pembed2003 | last post by:
Hi all, I asked this question in the C group but no one seems to be interested in answering it. :-( Basically, I wrote a search and replace function so I can do: char source = "abcd?1234?x"; char search = '?'; char* replace = "***"; char* result = search_and_replace(source,search,replace);
8
4032
by: Eric Lilja | last post by:
Hello, I had what I thought was normal text-file and I needed to locate a string matching a certain pattern in that file and, if found, replace that string. I thought this would be simple but I had problems getting my algorithm to work and in order to help me find the solution I decided to print each line to screen as I read them. Then, to my surprise, I noticed that there was a space between every character as I outputted the lines to the...
5
744
by: Bob | last post by:
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 '=" & Me! DoCmd.OpenForm stDocName, , , stLinkCriteria
93
2573
by: Matt | last post by:
Hi folks. Can you help with some questions? I gather that some types supported by g++ are nonstandard but have been proposed as standards. Are the long long and unsigned long long types still under consideration for the ANSI C and C++ standards? Are they likely to be accepted into the standards? Which compilers support those types, and which do not?
5
2629
by: pembed2003 | last post by:
Hi all, I need to write a function to search and replace part of a char* passed in to the function. I came up with the following: char* search_and_replace(char* source,char search,char* replace){ char* result; size_t l = strlen(source), r = strlen(replace), i; int number_of_replaces = 0; for(i = 0; i < l; i++){ if(source == search)
16
6157
by: BBM | last post by:
This is so bizarre I hesitate to post it, but I need to get this working. My code looks like this... Private Const cmdTestResourcesSel = "SELECT * FROM TResources" & _ " WHERE Scenario = @Scenario" Dim cmdstr as String cmdstr = cmdTestResourcesSel
16
2791
by: Rico | last post by:
I'm moving some queries out of an Access front end and creating views out of them in SQL Server 2005 express. In some of the numeric fields, I use nz quite often, ( i.e. nz(,0)) to return a zero if the field is null. Is there anything equivalent to this in SQL Server? Right now I'm using CASE WHEN ... but it seems like an awful lot of script to write just to replace null with a zero. Any help would be greatly appreciated. Thanks!
3
2998
by: Roy W. Andersen | last post by:
Hi, I need to do some replace-calls on certain strings in order to replace smiley glyphs and other keywords with graphical icons on the client. Unfortunately, my knowledge of regular expressions is somewhat limited to say the least, so I'm struggling with making it work as I wand. What I have is an associative array like this: smileys = 'smile.gif'; smileys = 'sad.gif';
270
9438
by: jacob navia | last post by:
In my "Happy Christmas" message, I proposed a function to read a file into a RAM buffer and return that buffer or NULL if the file doesn't exist or some other error is found. It is interesting to see that the answers to that message prove that programming exclusively in standard C is completely impossible even for a small and ridiculously simple program like the one I proposed. 1 I read the file contents in binary mode, what should...
32
2715
by: Stephen Horne | last post by:
I've been using Visual C++ 2003 for some time, and recently started working on making my code compile in GCC and MinGW. I hit on lots of unexpected problems which boil down to the same template issue. A noddy mixin layer example should illustrate the issue... class Base { protected: int m_Field;
0
8438
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8348
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8863
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8549
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6187
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4186
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4356
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2004
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1761
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.