Error 5 on button-click in Access 2003

  • Thread starter Thread starter Dave Stone
  • Start date Start date
D

Dave Stone

I have a form with a 'Close' button and the following OnClick event
proc.:

Private Sub Close_Form_Click()
On Error GoTo Err_Close_Form_Click


DoCmd.Close

Exit_Close_Form_Click:
Exit Sub

Err_Close_Form_Click:
MsgBox Err.Description
Resume Exit_Close_Form_Click

End Sub

Pretty simple, huh?

Click the button in Access XP and the form closes; do the same in
Access 2003 and I get 'Invalid procedure call or argument' (error 5)
and an empty Visual Basic window on dismissing the MsgBox. The
database file is 2002 format, by the way, and there are no missing
references AFAIK.

Any clues, anyone?

Dave
 
Decompile a copy of the database by entering something like this at the
command prompt while Access is not running. It is all one line, and include
the quotes:
"c:\Program Files\Microsoft office\office\msaccess.exe" /decompile
"c:\MyPath\MyDatabase.mdb"

When you reopen the database, compact it:
Tools | Database Utilities | Compact

Then change the DoCmd.Close line to:
DoCmd.Close acForm, Me.Name, acSaveNo

Then open the Immediate window (Ctrl+G), and check that it compiles okay:
Debug | Compile

If it still does not work, it has to be an issue with references. From the
code window, choose References on the Tools menu. Write down the names of
the selected libraries, and unselect them all except the VBA and Access ones
(which cannot be deselected.) Close Access. Restart.

Reselect the libraries. More on references:
http://members.iinet.net.au/~allenbrowne/ser-38.html
 
Thanks for this, Allen, but I'm not having any joy. I'm assuming your
advice relates to Access 2003, since that's where the problem's
arising....
Decompile a copy of the database by entering something like this at the
command prompt while Access is not running. It is all one line, and include
the quotes:
"c:\Program Files\Microsoft office\office\msaccess.exe" /decompile
"c:\MyPath\MyDatabase.mdb"

When you reopen the database, compact it:
Tools | Database Utilities | Compact

Then change the DoCmd.Close line to:
DoCmd.Close acForm, Me.Name, acSaveNo

Then open the Immediate window (Ctrl+G), and check that it compiles okay:
Debug | Compile
So I do all the above (in 2003), and it raises error 5 when I hit
Compile.
If it still does not work, it has to be an issue with references. From the
code window, choose References on the Tools menu. Write down the names of
the selected libraries, and unselect them all except the VBA and Access ones
(which cannot be deselected.) Close Access. Restart.
I deselect all but VBA and Access 11 .OLB and close everything, but
when I try to close Access itself, I get 'The Save operation failed'.
So the code and reference changes have to be abandoned to get out of
Access in order to restart.
 
Create another simple unbound form with a button named "Close_Form" and
nothing else.
Paste the same code into the event procedure.

Does this form work?

- No: There has to be a reference problem. Write down all the references
checked, and uncheck them all except the 2 that won't deselect (VBA and
Access). Compact. Close Access. Restart Access. Reselect the same
references. If they are not there, or won't reselect, re-register the
library. More info:
http://members.iinet.net.au/~allenbrowne/ser-38.html

- Yes: There has to be a corrupton problem. Rebuild the database using the 6
steps for the first symptom in this article:
http://members.iinet.net.au/~allenbrowne/ser-47.html

I'm surprised that the decompile did not work. Although A2002 and A2003 use
the same file format, the binary is different. Decomiling dumps the A2002
binary, so A2003 will generate its own. I would have expected that to work
unless the corruption is more widespread than expected.
 
Back
Top