Quit macro not working in runtime

O

Owl

This is the very first time I am using Runtime. I am using Runtime 2007 and
my Quit macro isn't working. What can I do about it?

Thanks for any replies.
 
D

Dirk Goldgar

Owl said:
This is the very first time I am using Runtime. I am using Runtime 2007
and
my Quit macro isn't working. What can I do about it?

Thanks for any replies.


What exactly are the actions in your Quit macro?

When you say "isn't working", what exactly do you mean? Do you get an error
message, or does nothing at all happen when you run it? How is the macro
invoked?
 
R

Rick Brandt

Owl said:
Thank you for your reply, Dirk.

The actions in my Quit macro (which works - to exit the database - on
every single other database I use OUT of Runtime) are simply Quit (and of
the options to Save or Prompt or Exit, I have selected Exit).

By not working, I mean it comes up with the following error message (THEN
paradoxically carries out the action requested):

You can’t carry out this action at the present time.
You tried to run a macro or used the DoCmd object in Visual Basic to carry
out an action. However, is performing another activity that prevents
this action from being carried out now.
For example, no actions on a form can be carried out while is repainting
a control or calculating an expression.
Carry out the action later.
Then there is an OK button and when I press the OK button, I am taken out
of the database as I wanted to be immediately with no further problem, but
I don't want the error message coming up.


The macro is invoked from a switchboard.

So far, I am using my database with Runtime on a computer WITH Access
2007, but am hoping to be able to try it out on a computer without Access
tonight -
hopefully I will have the Quit problem sorted out by then. I have Runtime
and my small simple application database file (not split - I am going to
try to do it with a copy of the database split when I have mastered this
unsplit one) in the same folder.

I have made the folder that they are in, a Trusted Location.

Does the Quit macro (when not using the runtime) close Access entirely or
just the file currently opened? The runtime cannot be used without a file
opened so the latter would not be allowed.
 
O

Owl

Thank you for your reply, Dirk.

The actions in my Quit macro (which works - to exit the database - on every
single other database I use OUT of Runtime) are simply Quit (and of the
options to Save or Prompt or Exit, I have selected Exit).

By not working, I mean it comes up with the following error message (THEN
paradoxically carries out the action requested):

You can’t carry out this action at the present time.
You tried to run a macro or used the DoCmd object in Visual Basic to carry
out an action. However, is performing another activity that prevents this
action from being carried out now.
For example, no actions on a form can be carried out while is repainting a
control or calculating an expression.
Carry out the action later.
Then there is an OK button and when I press the OK button, I am taken out of
the database as I wanted to be immediately with no further problem, but I
don't want the error message coming up.


The macro is invoked from a switchboard.

So far, I am using my database with Runtime on a computer WITH Access 2007,
but am hoping to be able to try it out on a computer without Access tonight -
hopefully I will have the Quit problem sorted out by then. I have Runtime
and my small simple application database file (not split - I am going to try
to do it with a copy of the database split when I have mastered this unsplit
one) in the same folder.

I have made the folder that they are in, a Trusted Location.


By the way, a separate issue and much less important to me right now (but I
don't know where to go to ask about this), for many months, I haven't been
"notified of replies" even when it has been a number of days before I have
come back into
Microsoft Discussions to see if somebody has replied to a question of mine.
Do you know which forum or where else I can go to ask for help on this? Or
do you know what I can do myself? I am clicking on Notify me of replies.
When this started (but I am not sure0 possibly co-incided with the time I had
a new hard drive put into my computer, some months ago.

Thanks for any more help you or anyone else gives me.
 
O

Owl

Oh, and further to this, this is happening in 2 separate attempts to use
Runtime with the application. The first is with an accdb file and the
necessary bit before the Target to direct the system to Runtime. The second
is with an accdr file. I have the 2 attempts in 2 separate folders, both
with Runtime in them.
 
O

Owl

Sorry, sorry, me again. I may have sorted out the minor Notify me of
replies. I have just seen the little icon in the bottom right corner that
allowed me to enable Notification. Presumably that will work now. I am
really sorry if you spent any time helping me with that before you see this.

Looking forward to help on the other problem, though - my Quit macro.
 
O

Owl

Thank you for your reply, Rick. The Quit macro (when not used in Runtime),
closes Access entirely. I think you meant that the former (being, closing
Access entirely) won't work. I appreciate being told that immensely. Every
bit I can learn about Runtime helps a lot because I am really floundering
with it. So, how can I have something on my switchboard to exit Access then?
 
O

Owl

I forgot to say that after I discovered the problem with I converted the
macro Quit to VBA and it is the following (but still coming up with the same
error message):

'------------------------------------------------------------
' Quit
'
'------------------------------------------------------------
Function Quit()
On Error GoTo Quit_Err

DoCmd.Quit acExit


Quit_Exit:
Exit Function

Quit_Err:
MsgBox Error$
Resume Quit_Exit

End Function
 
D

Dirk Goldgar

Owl said:
Thank you for your reply, Rick. The Quit macro (when not used in
Runtime),
closes Access entirely. I think you meant that the former (being, closing
Access entirely) won't work.

I don't think Rick means that at all. I think he means that the runtime
won't let you close the current database without exiting Access. I don't
know if that is true or not, but it makes sense.
 
D

Dirk Goldgar

Owl said:
I forgot to say that after I discovered the problem with I converted the
macro Quit to VBA and it is the following (but still coming up with the
same
error message):

'------------------------------------------------------------
' Quit
'
'------------------------------------------------------------
Function Quit()
On Error GoTo Quit_Err

DoCmd.Quit acExit


Quit_Exit:
Exit Function

Quit_Err:
MsgBox Error$
Resume Quit_Exit

End Function


I don't have a problem with either the Quit action in a macro or the
DoCmd.Quit method in VBA when running Access with the /runtime switch. I
don't have a runtime-only system to test on, but I don't think this can be
the basis of your problem.

It seems to me that your error message, "You can't carry out this action at
the present time," must be a clue to what is going on. Possibly there is
something going on in the database when you click the Quit button that is
either happening in runtime but not in normal mode, or vice versa. Is there
a record on a form that has been modified but can't be saved? Is there an
object whose design you have modified and can't save?

What happens if you open the database with no other objects open except a
simple unbound form that has only a button that invokes your Quit macro.
Does it still fail?
 
O

Owl

As regards your first question: "Is there an
object whose design you have modified and can't save?", No there isn't
anything like that.

As regards your second question: "What happens if you open the database with
no other objects open except a simple unbound form that has only a button
that invokes your Quit macro. Does it still fail?", I will try that.
 
O

Owl

I did what you asked and opened the database with
no other objects open except a simple unbound form that has only a button
that invokes your Quit macro. It worked. However, I need the macro to run
from the switchboard.

Thank you for any further help.
 
O

Owl

It didn't help. I am still not getting email notifications. Does anyone
know what I can do?

Thanks for any help.
 
D

Douglas J. Steele

Don't waste any time trying to get it to work.

Microsoft's web interface to these newsgroups has never really worked
properly, so even if you managed to get it working today, there's no
guarantee it'll work tomorrow.

And the fact that Microsoft is dropping these newsgroups in favour of new
web-based forums makes it even more futile to worry about it! <g>
 
O

Owl

Thank you for saving me a lot of time, Douglas. I actually put in a separate
question for this just before I found your reply.

I can hardly type I am laughing so much - I don't know if you will remember
this - but Wayne-I-M started a thread with the subject of Puzzling Americans
on 22/12/2006. Your response was brilliant and funny, but so was the whole
conversation, except Wayne's question which was a perfectly valid question,
but the seriousness - except for your response and those of one or two others
- of the conversation had me in stitches and still does. I put in a response
(to your response) about how my fellow South Africans would view it, if you
are interested to read it - well it is there, even if you aren't interested
to read it. Smiles.
 
D

Dirk Goldgar

Owl said:
I did what you asked and opened the database with
no other objects open except a simple unbound form that has only a button
that invokes your Quit macro. It worked. However, I need the macro to
run
from the switchboard.


That strongly suggests that there is something going on, possibly in your
switchboard form, possibly in some other code that is invoked by your
switchboard or by an autoexec macro, that is causing the difficulty. What
is the nature of your switchboard form? Is it the same sort of switchboard
that is constructed by the Access switchboard wizard? Have you modified the
code behind it? You may need to post the code.
 
O

Owl

Thanks, Dirk. Here is the code for my Switchboard. Yes, I fiddled with it
here and there, but I think it is back to what it was before (or at least,
more or less), except for the WarningsOn on Close.

Option Compare Database

Private Sub Form_Close()
DoCmd.SetWarnings (WarningsOn)

End Sub

Private Sub Form_Open(Cancel As Integer)
' Minimize the database window and initialize the form.

' Move to the switchboard page that is marked as the default.
Me.Filter = "[ItemNumber] = 0 AND [Argument] = 'Default' "
Me.FilterOn = True

End Sub

Private Sub Form_Current()
' Update the caption and fill in the list of options.

Me.Caption = Nz(Me![ItemText], "")
FillOptions

End Sub

Private Sub FillOptions()
' Fill in the options for this switchboard page.

' The number of buttons on the form.
Const conNumButtons = 8

Dim con As Object
Dim rs As Object
Dim stSql As String
Dim intOption As Integer

' Set the focus to the first button on the form,
' and then hide all of the buttons on the form
' but the first. You can't hide the field with the focus.
Me![Option1].SetFocus
For intOption = 2 To conNumButtons
Me("Option" & intOption).Visible = False
Me("OptionLabel" & intOption).Visible = False
Next intOption

' Open the table of Switchboard Items, and find
' the first item for this Switchboard Page.
Set con = Application.CurrentProject.Connection
stSql = "SELECT * FROM [Switchboard Items]"
stSql = stSql & " WHERE [ItemNumber] > 0 AND [SwitchboardID]=" &
Me![SwitchboardID]
stSql = stSql & " ORDER BY [ItemNumber];"
Set rs = CreateObject("ADODB.Recordset")
rs.Open stSql, con, 1 ' 1 = adOpenKeyset

' If there are no options for this Switchboard Page,
' display a message. Otherwise, fill the page with the items.
If (rs.EOF) Then
Me![OptionLabel1].Caption = "There are no items for this switchboard
page"
Else
While (Not (rs.EOF))
Me("Option" & rs![ItemNumber]).Visible = True
Me("OptionLabel" & rs![ItemNumber]).Visible = True
Me("OptionLabel" & rs![ItemNumber]).Caption = rs![ItemText]
rs.MoveNext
Wend
End If

' Close the recordset and the database.
rs.Close
Set rs = Nothing
Set con = Nothing

End Sub

Private Function HandleButtonClick(intBtn As Integer)
' This function is called when a button is clicked.
' intBtn indicates which button was clicked.

' Constants for the commands that can be executed.
Const conCmdGotoSwitchboard = 1
Const conCmdOpenFormAdd = 2
Const conCmdOpenFormBrowse = 3
Const conCmdOpenReport = 4
Const conCmdCustomizeSwitchboard = 5
Const conCmdExitApplication = 6
Const conCmdRunMacro = 7
Const conCmdRunCode = 8
Const conCmdOpenPage = 9

' An error that is special cased.
Const conErrDoCmdCancelled = 2501

Dim con As Object
Dim rs As Object
Dim stSql As String

On Error GoTo HandleButtonClick_Err

' Find the item in the Switchboard Items table
' that corresponds to the button that was clicked.
Set con = Application.CurrentProject.Connection
Set rs = CreateObject("ADODB.Recordset")
stSql = "SELECT * FROM [Switchboard Items] "
stSql = stSql & "WHERE [SwitchboardID]=" & Me![SwitchboardID] & " AND
[ItemNumber]=" & intBtn
rs.Open stSql, con, 1 ' 1 = adOpenKeyset

' If no item matches, report the error and exit the function.
If (rs.EOF) Then
MsgBox "There was an error reading the Switchboard Items table."
rs.Close
Set rs = Nothing
Set con = Nothing
Exit Function
End If

Select Case rs![Command]

' Go to another switchboard.
Case conCmdGotoSwitchboard
Me.Filter = "[ItemNumber] = 0 AND [SwitchboardID]=" &
rs![Argument]

' Open a form in Add mode.
Case conCmdOpenFormAdd
DoCmd.OpenForm rs![Argument], , , , acAdd

' Open a form.
Case conCmdOpenFormBrowse
DoCmd.OpenForm rs![Argument]

' Open a report.
Case conCmdOpenReport
DoCmd.OpenReport rs![Argument], acPreview

' Customize the Switchboard.
Case conCmdCustomizeSwitchboard
' Handle the case where the Switchboard Manager
' is not installed (e.g. Minimal Install).
On Error Resume Next
Application.Run "ACWZMAIN.sbm_Entry"
If (Err <> 0) Then MsgBox "Command not available."
On Error GoTo 0
' Update the form.
Me.Filter = "[ItemNumber] = 0 AND [Argument] = 'Default' "
Me.Caption = Nz(Me![ItemText], "")
FillOptions


' Run a macro.
Case conCmdRunMacro
DoCmd.RunMacro rs![Argument]

' Run code.
Case conCmdRunCode
Application.Run rs![Argument]

' Open a Data Access Page
Case conCmdOpenPage
DoCmd.OpenDataAccessPage rs![Argument]

' Any other command is unrecognized.
Case Else
MsgBox "Unknown option."

End Select

' Close the recordset and the database.
rs.Close

HandleButtonClick_Exit:
On Error Resume Next
Set rs = Nothing
Set con = Nothing
Exit Function

HandleButtonClick_Err:
' If the action was cancelled by the user for
' some reason, don't display an error message.
' Instead, resume on the next line.
If (Err = conErrDoCmdCancelled) Then
Resume Next
Else
MsgBox "There was an error executing the command.", vbCritical
Resume HandleButtonClick_Exit
End If

End Function
 
D

Dirk Goldgar

Owl said:
Thanks, Dirk. Here is the code for my Switchboard. Yes, I fiddled with
it
here and there, but I think it is back to what it was before (or at least,
more or less), except for the WarningsOn on Close.

Option Compare Database

Private Sub Form_Close()
DoCmd.SetWarnings (WarningsOn)

End Sub


That code is wrong, though, unless you have somewhere defined a global
variable named "WarningsOn". If your purpose is to turn warnings on, you
should write:


DoCmd.SetWarnings True

or

DoCmd.SetWarnings -1

However, if your switchboard is to remain open all the time the database is
open, I don't see any point in turning the warnings on while the database is
closing. I don't believe that command will have any effect when the
database reopens -- the warning settings at that time will be determined by
various option settings.

I have no idea whether the incorrect code in the Close event has any bearing
on your problem, I'm afraid.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top