Very Strange VBA Problem (1 Viewer)

cblaine99

Registered User.
Local time
Yesterday, 17:21
Joined
Mar 10, 2016
Messages
29
I am running Access 2007. I have an .mdb database, and it works fine.

BUT, I am unable to make any change whatsoever to the VBA code without causing an error when I try to open the database. For example, I view the code for Form_frmMenu. Inside a function, on a blank line, I enter the code x=1. I save the form module, close the database. When I try to launch the database I get the message "An error has occurred trying to open...".

I don't think I've corrupted my copy of Access 2007 because I can open the Northwind database that Microsoft provides, make changes to the VBA code, save it and run it successfully.

So, to summarize, in this one particular database, if I enter any VBA code whatsoever, the database will not launch.

I hope someone can help.

Thank you.
 

JHB

Have been here a while
Local time
Today, 02:21
Joined
Jun 17, 2012
Messages
7,732
Try "Compact & Repair" the database.
Else create a new database and import all into it from the "old" database.
 

Anakardian

Registered User.
Local time
Today, 02:21
Joined
Mar 14, 2010
Messages
173
You can also try to start the file with the /decompile flag.

Example: "C:\Program Files\Microsoft Office\Office14\MSACCESS.EXE" "Path to your file" /decompile

Save the above in a .bat file and see it if helps.
It works when there is something wrong with compiled vba and forces it to compile it again when needed.
 

cblaine99

Registered User.
Local time
Yesterday, 17:21
Joined
Mar 10, 2016
Messages
29
Thank you both to Anakardian and JHB. Your advice is appreciated.

I have discovered the cause of the problem. When I declared a function I used a "$" character in the function name:

Function FixString$(s) <--- doesn't work

When I removed the $ from the function name everything works normally.

Function FixString(s) <--- works

Thanks again for your help.
 

Users who are viewing this thread

Top Bottom