Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
4.56/5 (2 votes)
See more:
In my current role I inherited (I must have been evil in a previous life) some MS Access VBA which has been working for years.

Today it randomly started throwing errors. I tracked it down to a piece of code that uses the old on-error-resume-next trick that VB6 and VBA programmers had to use in the absence of decent error handling.

The minimum code that I can recreate the problem with is...
VB
On Error Resume Next
ws.Range("A1:K18").Replace "", "0"
On Error GoTo 0
Where ws is a worksheet in an Excel workbook (that was added in the Access VBA) and the range is filled with data (no empty cells) (As, if there are empty cells then Replace does not throw up the "I can't find anything to replace" message that I'm trying to avoid)

I've tried all the usual stuff (see below) to no avail. Interesting, MS Excel does not seem to be affected.

The way around this specific problem is obviously to do a Find first and only issue the Replace command if it is necessary. However, I'm conscious that there are hundreds of EUP solutions out in the business and I would like to find a generic fix if possible.

This is Windows 10, Office 365 ProPlus with Access Version 1803 (Build 9126.2351) i.e. VBA Retail 7.1, No Office updates have been applied since it last worked.

What I have tried:

- Checking the IDE,Tools, Options, General, Error Trapping hadn't been changed to "Break on All Errors"
- Tried all combinations of that setting
- Compact and Repaired the database
- Fully decompiled the database in question and recompiled
- applied a gpupdate /force and hard reboot
Posted
Updated 24-Apr-19 9:14am
Comments
Maciej Los 6-Feb-19 14:23pm    
Caroline, years ago i've been in the same position. The reason was very strange, because something happend with modules (i've found unidentified sign/character).
How to walkaroud this? Export and remove all modules (user forms too), then compact and repair database. Inspect files. Finally, import modules and again compact and repair. Let me know if it helps.
CHill60 8-Feb-19 4:31am    
Well 47 modules later .. I'm afraid it didn't work :-(
I don't have administrator rights on my machine so couldn't run sfc but the same issue can be reproduced on various machines. Ironically if I just put the absolute bare minimum of code into a new database it doesn't reproduce the error!
I'm fairly confident now that all the other stuff isn't going to suddenly fall apart so I've just released the "see if it's there before attempting to replace" fix.
Strange though.
Thanks for trying
C
Maciej Los 8-Feb-19 5:00am    
I've got another idea. Please, check if there's a situation, which has been described by MSDN: "If the calling procedure has an enabled error handler, it is activated to handle the error."
On Error statement (VBA) | Microsoft Docs[^]
CHill60 8-Feb-19 8:21am    
So I took out all of the error handling except the bit around my tiny snippet - still didn't work I'm afraid.
Maciej Los 8-Feb-19 8:50am    
Well, you've got a hard nut to crack...

I'd call service staff to provide procedure with:
- file system checking,
- HDD area checking and repairing
- system cleaning (remove unnecesarry restore points, )
- etc.
This should help!

If it'll NOT help, there'll be last thing to do:
Create new database. Insert new module and paste your short code snippet. Import all tables and queries. Then import modules (UserForms), but not all in the time. Import one-by-one and after each import, compile code, compact and repair database and finally check if your code snippet is working. There must be something what causes such of strange behaviour.

I'm keeping my fingers for you, Caroline. I hope it helps t resolve your issue.

Cheers
Maciej

1 solution

As we agreed with Caroline in the comments to the question, i would like to share my ways i've resolved such of issues...

Method #1 - in case when unidentified signs/characters have been found in one or more modules:

  • export and remove all modules (UserForms too)
  • then compact and repair database
  • inspect files and edit with notepad - if necessary
  • import modules and compact and repair database again


Method #2 - in case when method #1 won't help

  • create new database
  • import tables and queries, then import modules (even UserForms), but not all in the time!
        Note: import one-by-one to detect which one is broken... And after each import, compile code, compact and repair database


Method #3 - in case when method #2 won't help:


Method #4 - in case when none of above methods help:
  • repair or reinstall MS Office


Good luck!
 
Share this answer
 
Comments
phil.o 24-Apr-19 15:42pm    
Impressive effort :)
That remembers me a few years ago when I had to help a friend get rid of an issue with his VBA code... What an headache!
Maciej Los 24-Apr-19 15:50pm    
Oh yeah!
CHill60 25-Apr-19 3:38am    
5'd. Thanks for sticking with me through the journey!
Maciej Los 25-Apr-19 8:17am    
Thank you, Caroline.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900