problem with switchboard and run code

alant37

Registered User.
Local time
Today, 18:59
Joined
Jun 8, 2005
Messages
10
Im new to VBA and Im trying to run the following module called quit from the standard switchboard:
Public Function quit()
On Error GoTo quit_Err
DoCmd.quit acSave
quit_Exit:
Exit Function
quit_Err:
MsgBox Error$
Resume quit_Exit
End Function

In the standard switchboard I am using the Command: Run Code and a Function name: quit. However, I get the error message 'There was an error executing the command'. Is there anyway of using the standard switchboard to achieve this?
 
My guess he is confusing the acSave option with the notion it is saving the current record when in fact the acSave option saves any unsaved "object" changes, not "record" changes.

Code:
Public Sub CloseDatabase()
On Error GoTo CloseDatabase_Err
    
    Application.Quit acQuitSaveNone
    
CloseDatabase_Exit:
    Exit Sub
    
CloseDatabase_Err:
    MsgBox Err.Number & " - " & Err.Description
    Resume CloseDatabase_Exit
    
End Sub
 
Last edited:
Why are you making a Quit function when Access already has built in calls?
 
The only limitation is you cannot pass variables through your functions
With a minor tweak to the switchboad code it can be persuaded to take variables :rolleyes:

if you change :-
' Run code.
Case conCmdRunCode
Application.Run rst![Argument]

To :-

' Run code.
Case conCmdRunCode
Eval (rst![Argument])

Then it should run the arguments OK, bear in mind that you will now have to call all code using brackets!
MyFunc() not MyFunc

HTH

Peter
 
Thanks everyone, its working now as the following subroutine:
Public Sub fQuit()
On Error GoTo fQuit_Err

Application.quit acQuitSaveNone

fQuit_Exit:
Exit Sub

fQuit_Err:
MsgBox Error$
Resume fQuit_Exit

End Sub

However, I was still getting the error message until I changed the module name from fquit to converted-fquit. The code that I first produced was from converting a macro, but after reading your posts I have changed it to the code above.
 
Modules should never have the same name as a function/sub
 
alant37 said:
Thanks everyone, its working now as the following subroutine:
Public Sub fQuit()
On Error GoTo fQuit_Err

Application.quit acQuitSaveNone

fQuit_Exit:
Exit Sub

fQuit_Err:
MsgBox Error$
Resume fQuit_Exit

End Sub

However, I was still getting the error message until I changed the module name from fquit to converted-fquit. The code that I first produced was from converting a macro, but after reading your posts I have changed it to the code above.
You should not have a module for every function. Don't put all your eggs [public functions/subs] in one basket but do not create a module for every public function/sub. But Bat17 is correct that you can not name a module and a function/sub with the same name. Why did you name the sub fQuit? What does the f stand for? Also, your error message is lacking the runtime error number for which is very helpful to debugging and trapping for specific errors. In my biased opinion this is a better way to code your shutdown sub...
Code:
Public Sub CloseDatabase()
On Error GoTo CloseDatabase_Err
    
    Application.Quit acQuitSaveNone
    
CloseDatabase_Exit:
    Exit Sub
    
CloseDatabase_Err:
    MsgBox Err.Number & " - " & Err.Description
    Resume CloseDatabase_Exit
    
End Sub
 

Users who are viewing this thread

Back
Top Bottom