473,394 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

error handling overriding normal situation

I have a button in my database with common error handling code. My problem is, there's a normal situation (no bids for a job) that I want to use a message box to explain to the user but the error handling takes over.

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnSubmit_Click()
  2. On Error GoTo Err_btnSubmit_Click
  3. ...
  4. 'below is what I want to happen if emplid is 0
  5. If (rstPostings("EmplID")) = 0 Then
  6.     MsgBox "There are no bids for this position"
  7. Else
  8. ...
  9. End If
  10. ...
  11. 'below is what takes over
  12. Err_btnSubmit_Click:
  13.     MsgBox "You Must Select 'Accepted' Or 'Rejected'"
I used the ... to replace a lot of code which works ok.

I'd appreciate any help you can provide!
Jan 30 '16 #1
5 1033
zmbd
5,501 Expert Mod 4TB
So what have you done to trouble shoot this? What error are you actually getting? You say your code that you've omitted works, yet, the error trap is invoking prior (?) to the section you've posted; thus, something doesn't work in your code that you've omitted for the situation you describe.

>>> Insert a STOP at the beginning of your code and step thru it.

You might want to also follow the troubleshooting section of:
[*] > Before Posting (VBA or SQL) Code
This may catch a few other bugs in the code :) .
Jan 30 '16 #2
NeoPa
32,556 Expert Mod 16PB
If you have a special situation which you'd like to be handled differently from the default then you'll need to be able to recognise that situation in your error-handling code. Generally that will be a specific error number (Err.Number).

In your error handler you'll need to recognise the situation and follow different paths depending on the situation identified by your code.
Jan 30 '16 #3
I've made a change since the first posting once I realized EmplID is a text field. Now it says:
Expand|Select|Wrap|Line Numbers
  1. If (rstPostings("EmplID")) = "" Then
  2.  
  3.     MsgBox "There are no bids for this position"
  4. Else
  5. ...
  6. Err_btnCommand18_Click:
  7.     MsgBox "You Must Select the Job to be Filled"
  8.  
As I step through the code, everything is fine if EmplID isn't blank but if it is, the code skips the "There are no bids for this position" message and goes to the "You must choose accepted or rejected" message.
I'm assuming the problem has to do with an error in the If statement but I can't figure it out.
Jan 30 '16 #4
zmbd
5,501 Expert Mod 4TB
Change your testing from:
If (rstPostings("EmplID")) = "" Then

to
If (rstPostings("EmplID") & "") = "" Then

to be sure, it's a subtle change; however, more effective in catching both zero-string and null values.
Jan 31 '16 #5
NeoPa
32,556 Expert Mod 16PB
In many cases fields that have no visible content are not empty strings, as you've tested for, but Nulls.

NB. Nulls are not values like strings and numbers are, but are a special value that rather indicate the lack of any usable value.

Unfortunately, String fields can be complicated as they can be set to allow empty string values as well as Nulls. Hence the complicated way to test for a string value with actual characters in it.

There are various possibilities for this :
Expand|Select|Wrap|Line Numbers
  1. If Nz(rstPostings("EmplID"), "") = "" Then ...
  2. If (rstPostings("EmplID") & "") = "" Then ...
  3. If Not rstPostings("EmplID") > "" Then ...
Personally, I prefer the last of those, but all would work reliably for you.
Jan 31 '16 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Christian Christmann | last post by:
Hi, assert and error handling can be used for similar purposes. When should one use assert instead of try/catch and in which cases the error handling is preferable? I've read somewhere that...
2
by: deko | last post by:
I want to turn error handling off, then back on in a sub routine that backs up a select set of documents. For some reason, I can't seem to get this to work - Private Sub BackupDocs() On Error...
21
by: Anthony England | last post by:
Everyone knows that global variables get re-set in an mdb when an un-handled error is encountered, but it seems that this also happens when the variable is defined as private at form-level. So...
3
by: Alberto Giménez | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi there! I'm doing some homework (almost finished), but now i'm reconsidering a design decission I made at the beginning. This is about error...
7
by: Spacen Jasset | last post by:
The main two desirable things I feel error handling should provide are these: 1) Debugging and diagnostic aid 2) User feedback One method that is used a fair amount it to 'say' that all...
4
by: aaj | last post by:
Hi all I have an automated application, that runs in the middle of the night. If certain 'non system' errors occur (things like malformed files, missing files etc..), I send an automatic Email...
14
by: Al Smith | last post by:
I need help in implementing proper error handling. I am trying to upload a file based on the sample code below. The code works well except if the file selected is too big. I do know about the...
1
by: Metal Dave | last post by:
I do not understand the error handling of SQL Server here. Any error in bulk insert seems to halt the current T-SQL statement entirely, rendering it impossible to log an error. The first statement...
10
by: Anthony England | last post by:
(sorry for the likely repost, but it is still not showing on my news server and after that much typing, I don't want to lose it) I am considering general error handling routines and have...
35
by: jeffc226 | last post by:
I'm interested in an idiom for handling errors in functions without using traditional nested ifs, because I think that can be very awkward and difficult to maintain, when the number of error checks...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.