473,386 Members | 1,841 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,386 software developers and data experts.

On Error GoTo ... not consistent (Access 2000 on XP)

I'm in a spot of bother... just spent 6 hours trying to figure this one out - getting very frustrated...

I have seen many posts on this site and some others... all touching on this subject but not quite giving me the answer (but boy have I learned a lot !)

Problem is, in VB in Access 2000, On Error GoTo .. is not consistent...

On Error # 1 works... (ie, table "In Development" does not exist and code jumps to In_Production)
On Error # 2 does not work... I get a MS VB Runtime error 3078
been trying dozens of different approaches...

What am I trying to do ? If a file does not exist, I want to jump and run some specific code...

btw, Tools>Options>General>Error Trapping is set to "Break on Unhandled Errors"

Any suggestions ? Anyone else come across this problem ?

Many thanks in advance...

Expand|Select|Wrap|Line Numbers
  1. <start code>
  2. ...
  3. On Error GoTo In_Production   '** # 1 **
  4. Set InDevelopment = MyDb.OpenRecordset("In Development")
  5. y = InDevelopment.RecordCount
  6.  
  7. In_Development:
  8. MsgBox "You are in V5 Development - no changes will occur."
  9. Exit Function
  10.  
  11. In_Production:
  12. Countrecs = MySet.RecordCount
  13. Msg = "Reconnecting Databases"
  14. ReturnValue = SysCmd(SYSCMD_INITMETER, Msg, Countrecs)
  15. x = 1
  16.  
  17. On Error GoTo Next_Stage   '** # 2 **
  18. Set InDevelopment = MyDb.OpenRecordset("In Development")
  19. p = p + 1
  20.  
  21. Next_Stage:
  22. ... additional code...
  23.  
  24. <end code>
John
Dec 9 '06 #1
5 2042
MMcCarthy
14,534 Expert Mod 8TB
I an having a problem following your logic. However, one thing I've noticed is that you tell the code in error one to go to In_Development and in Error 2 to go to Next_Stage but if error 1 is not found then the recordset

Set InDevelopment = MyDb.OpenRecordset("In Development")

is opened twice.

I think your problem is in your logic.

Remember if an error is not found then the code will procede and the steps you are marking in the code are only bookmarks. They do not stop the rest of the code that following being processed.

For example:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Stage1:
  3.    Code1a
  4.    On Error GoTo Stage3 ' This will skip Stage2 but will complete all code sequentially from then on including Stage4.
  5.    Code1b
  6.    On Error GoTo Stage4 ' This will skip Stage2 and Stage3 but will complete all code sequentially from Stage4 on.
  7.  
  8. Stage2:
  9.    Code2
  10.    On Error GoTo Stage1 ' This will return to Stage1 and repeat all the code sequentially from that point.  Therefore if the error in this stage is never resolved or you don't hit the error handler in Stage1 you would end up in an endless loop.
  11.  
  12. Stage3:
  13.    Code3
  14.  
  15. Stage4:
  16.    Code4
  17.  
  18.  
Mary
Dec 9 '06 #2
NeoPa
32,556 Expert Mod 16PB
You could try entering
Expand|Select|Wrap|Line Numbers
  1. On Error GoTo 0
in the code where it is no longer appropriate to trap the error in the way defined.
You haven't stated, but I'm assuming the error message comes up and the code is stopped on the
Expand|Select|Wrap|Line Numbers
  1. Set InDevelopment = MyDb.OpenRecordset("In Development")
line.
Dec 10 '06 #3
NeoPa
32,556 Expert Mod 16PB
This only goes wrong when BOTH errors are triggered right?
That's because you can't trigger error code while you're still in an error routine.
You need to issue a Resume command (or exit the scope) before the error code can be triggered again.

For your type of situation where you want to throw an error but continue processing consider using
Expand|Select|Wrap|Line Numbers
  1. On Error Resume Next
to get past lines that are likely to error.
Dec 10 '06 #4
Thanks NeoPa - your thoughts gave me some ideas and I have now been able to successfully run my code...

your words "... you can't trigger error code while you're still in an error routine..." gave me some ideas... I'm now using :

On Error Resume Next
... VB statement (may be in error)
If Err.Number = 1234 then
... execute some more code
... End If

Using this method, the error is handled in my code, not by VB/Access.

Thanks again.

John
Dec 10 '06 #5
NeoPa
32,556 Expert Mod 16PB
My pleasure - and thanks for the reply. It does help.
Dec 10 '06 #6

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

Similar topics

6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
14
by: Abhi | last post by:
FYI: This message is for the benefit of MS Access Community. I found that this prblem has been encounterd by many but there is hardly any place where a complete solution is posted. So I thought...
34
by: electrician | last post by:
Perl has it, Basic has it, Fortran has it. What is so difficult about creating a goto command for JavaScript. Just set up a label and say go to it.
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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
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...
0
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,...
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...

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.