How to stop macro from code

L

Lee Hunter

I have a function called from a macro. I would like to stop the macro from
further execution from within the function. There is no form or reports
associated with the macro or function to use macro SetCondition.

I have tried Send Keys "^{BREAK" but it seems tio be ignored.

Any thoughts?

Thanks,
Lee
 
L

Lee Hunter

Thanks for the reply Rick,

My problem is that RunCommand Zoom100% only works from a macro and then
only when the report is run from the macro. If I try to use it from within
the sub (function) I get a run time error saying the zoom command isn't
available now.

I want to test, within the sub, and not run the report and stop the macro
accordingly.

Any thoughts?

Thanks,
Lee
 
L

Lee Hunter

Yep, that the very code I use, but it produces the run time error.
Here the whole code snippet

strSQL = "SELECT QC.* FROM QC WHERE (((DateDiff('d', Now(),
[QC]![RecvDate])) < 2));"
Set Rs = CDb.OpenRecordset(strSQL)
If Rs.RecordCount > 0 Then
Beep
MsgBox "You Have Over Due QCNs", vbCritical, "Over DUe QCNs"
DoCmd.OpenReport "QC", acViewPreview, "", "", acNormal
DoCmd.Maximize
DoCmd.RunCommand acCmdZoom100
End If
Rs.Close

Any other ideas?

Thanks!
 
R

Rick Brandt

Lee said:
Yep, that the very code I use, but it produces the run time error.
Here the whole code snippet

strSQL = "SELECT QC.* FROM QC WHERE (((DateDiff('d', Now(),
[QC]![RecvDate])) < 2));"
Set Rs = CDb.OpenRecordset(strSQL)
If Rs.RecordCount > 0 Then
Beep
MsgBox "You Have Over Due QCNs", vbCritical, "Over DUe QCNs"
DoCmd.OpenReport "QC", acViewPreview, "", "", acNormal
DoCmd.Maximize
DoCmd.RunCommand acCmdZoom100
End If
Rs.Close

Any other ideas?

Try putting the DoCmd.Maximize in the report's Open event and removing it from
this code.

I use those lines all the time without any trouble.
 
B

Bas Cost Budde

PMFJI;
I've been following this thread.

Lee said:
DoCmd.OpenReport "QC", acViewPreview, "", "", acNormal

isn't here one parameter too much?
DoCmd.Maximize
DoCmd.RunCommand acCmdZoom100

With me, this works just fine! How about On Error Resume Next?
 
B

Bas Cost Budde

The first and foremost issue with macros is that they don't provide
error handling!
 
L

Lee Hunter

Thanks Rick,

Tried moving only the Maximize, then both.

Private Sub Report_Open(Cancel As Integer)
DoCmd.Maximize
DoCmd.RunCommand acCmdZoom100
End Sub

It resulted in the same

Run-Time error '2056'
The command or action 'Zoom100%' insn't available now.

I even moved the code to a Sub and called the Sub from the Function, all to
no avail.

Is there any hope?

Lee



Rick Brandt said:
Lee said:
Yep, that the very code I use, but it produces the run time error.
Here the whole code snippet

strSQL = "SELECT QC.* FROM QC WHERE (((DateDiff('d', Now(),
[QC]![RecvDate])) < 2));"
Set Rs = CDb.OpenRecordset(strSQL)
If Rs.RecordCount > 0 Then
Beep
MsgBox "You Have Over Due QCNs", vbCritical, "Over DUe QCNs"
DoCmd.OpenReport "QC", acViewPreview, "", "", acNormal
DoCmd.Maximize
DoCmd.RunCommand acCmdZoom100
End If
Rs.Close

Any other ideas?

Try putting the DoCmd.Maximize in the report's Open event and removing it from
this code.

I use those lines all the time without any trouble.
 
L

Lee Hunter

The problem is not controlling the error, but getting the zoom to work. As
you can see from my last relpy to Rick, I gone to extreme measures and still
get the error.

What kind of environment problems might I be having to cause the error?

Lee
 
L

Lee Hunter

The funny part is, if I move the code to open report, maximize and zoom from
the module into the macro, it all works.

What do you make of that?

Lee
 
B

Bas Cost Budde

How about

application.runcommand

instead of

docmd.runcommand

?

Lee said:
Thanks Rick,

Tried moving only the Maximize, then both.

Private Sub Report_Open(Cancel As Integer)
DoCmd.Maximize
DoCmd.RunCommand acCmdZoom100
End Sub

It resulted in the same

Run-Time error '2056'
The command or action 'Zoom100%' insn't available now.

I even moved the code to a Sub and called the Sub from the Function, all to
no avail.

Is there any hope?

Lee



:

Lee said:
Yep, that the very code I use, but it produces the run time error.
Here the whole code snippet

strSQL = "SELECT QC.* FROM QC WHERE (((DateDiff('d', Now(),
[QC]![RecvDate])) < 2));"
Set Rs = CDb.OpenRecordset(strSQL)
If Rs.RecordCount > 0 Then
Beep
MsgBox "You Have Over Due QCNs", vbCritical, "Over DUe QCNs"
DoCmd.OpenReport "QC", acViewPreview, "", "", acNormal
DoCmd.Maximize
DoCmd.RunCommand acCmdZoom100
End If
Rs.Close

Any other ideas?

Try putting the DoCmd.Maximize in the report's Open event and removing it from
this code.

I use those lines all the time without any trouble.
 
R

Rick Brandt

Lee said:
The problem is not controlling the error, but getting the zoom to
work. As you can see from my last relpy to Rick, I gone to extreme
measures and still get the error.

What kind of environment problems might I be having to cause the
error?

The form you are calling this from is not Modal by any chance is it?
 
L

Lee Hunter

Hi Rick,

No, this is being called from an autoexec macro, set off by an XP scheduled
task to check a table for data within a date range. If data exists, then the
report./query is executed. I don't know if I want to ruin the report until
the query is run and has ouput. if not, then I want to quit / stop the macro
at that point.

The reason for the macro and not VBA code is that acZoom100 does not
function within code but it's equivelant does work from a macro.

Does that help you understand?

Thanks,
Lee
 
R

Rick Brandt

Lee said:
Hi Rick,

No, this is being called from an autoexec macro, set off by an XP
scheduled task to check a table for data within a date range. If
data exists, then the report./query is executed. I don't know if I
want to ruin the report until the query is run and has ouput. if
not, then I want to quit / stop the macro at that point.

The reason for the macro and not VBA code is that acZoom100 does not
function within code but it's equivelant does work from a macro.

Does that help you understand?

What I don't understand is why you can't get acZoom100 to work in code. I do
this all the time so it SHOULD work.

I'm also having a bit of difficulty understanding the need to preview a report
as a scheduled task. What if no one is sitting at the computer? Isn't it a bit
like the tree falling in the forest with no one there to hear it?
 
L

Lee Hunter

Hi Rick,

Sorry for the delay, the company's been down for summer shutdown.

The reason for the preview on a scheduled task is that this is a crticial
application. We have responses that have to be made within a certain period.
The app starts at a certain time, checks to see if any responses are due
today, then previews the report to show which ones are due. Obviously, if
none are found then the report is not necessary.

If I can get the zoom to work from code then I'm home free. Any ideas why
it's failing for me? Is there any data I can provide to help you?

Thanks,
Lee
 
Top