473,412 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

Action on Error Condition with MACROS

Hi:

I have a MACRO and as one step in it I am opening a form, which is based on a query. The
query calls for entry of a portion of an associates name as the selection criteria for
records. Using the form : Like [ Enter first letters of Associates Name: ] & "*"

The snag is that the box that comes up offers the opportunity to click on "Cancel". When
the user clicks on "Cancel" (intending to stop the process) the system appears to close
out totally. In other words, there is no program response to the cancel command. With a
macro, I would like to be able to intercept the Cancel call, and close the macro without
any further action. Is there some other way to do this, or have I got myself in a hopeless
snarl? I tried putting a close on no data macro in the form, but that does not appear to
do the job either.

Best

John Baker
Nov 12 '05 #1
4 5524
Macros have no error handling.

As you found, they are only useful for a *very* limited range of things.

Looks like you have outgrown them, and it's time to dip your feet into VBA
where error handling is part of every procedure you write.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"John Baker" <Ba******@Verizon.net> wrote in message
news:an********************************@4ax.com...

I have a MACRO and as one step in it I am opening a form, which is based on a query. The query calls for entry of a portion of an associates name as the selection criteria for records. Using the form : Like [ Enter first letters of Associates Name: ] & "*"
The snag is that the box that comes up offers the opportunity to click on "Cancel". When the user clicks on "Cancel" (intending to stop the process) the system appears to close out totally. In other words, there is no program response to the cancel command. With a macro, I would like to be able to intercept the Cancel call, and close the macro without any further action. Is there some other way to do this, or have I got myself in a hopeless snarl? I tried putting a close on no data macro in the form, but that does not appear to do the job either.

Best

John Baker

Nov 12 '05 #2
Thanks.

Unfortunately my VBA sills are very very limited.

How would I open a form (based on a query), check for an error and then close the form if
there was an error,or return to the main macro?

If you could give me a simple outline of the commands required to do this it would be a
great help.

Thanks

John baker

"Allen Browne" <Al*********@SeeSig.Invalid> wrote:
Macros have no error handling.

As you found, they are only useful for a *very* limited range of things.

Looks like you have outgrown them, and it's time to dip your feet into VBA
where error handling is part of every procedure you write.


Nov 12 '05 #3
In the Database window, choose the Modules tab, and click New.

In the new module, create a function by typing:
Function WhateverYouWantToCallIt()
Access adds
End Function

Between the 2 lines, enter:
DoCmd.OpenForm "Form1"
Include the quotes. Replace Form1 with the name of your form.

To call the function from the macro, use the RunCode action. That's the
basics.
Here's a more comprehensive example.
Save the code below into your module.

In your macro, choose the StopMacro action, and put this beside it in the
Condition column (View menu if you don't see a Condition column):
Not FormOpened("Form1")
This will cause the macro to stop if the form did not open; otherwise it
continues to the next line.

For more information about error handling, see:
Error Handling in VBA
at:
http://allenbrowne.com/ser-23a.html

----------code starts-----------
Function FormOpened(strForm As String) As Boolean
On Error GoTo Err_Handler
'Argument: Name of the form to open
'Return: True if the form opened.

DoCmd.OpenForm strForm
FormOpened = True

Exit_Handler:
Exit Function

Err_Handler:
If Err.Number <> 2501 Then
MsgBox "Error " & Err.Number & " - " & Err.Description
End If
Resume Exit_Handler
End Function
----------code ends-----------

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"John Baker" <Ba******@Verizon.net> wrote in message
news:nt********************************@4ax.com...
Thanks.

Unfortunately my VBA sills are very very limited.

How would I open a form (based on a query), check for an error and then close the form if there was an error,or return to the main macro?

If you could give me a simple outline of the commands required to do this it would be a great help.

Thanks

John baker

"Allen Browne" <Al*********@SeeSig.Invalid> wrote:
Macros have no error handling.

As you found, they are only useful for a *very* limited range of things.

Looks like you have outgrown them, and it's time to dip your feet into VBAwhere error handling is part of every procedure you write.

Nov 12 '05 #4
Allen:

Thank you very much indeed. This was most helpful.

Regards

John Baker

"Allen Browne" <Al*********@SeeSig.Invalid> wrote:
In the Database window, choose the Modules tab, and click New.

In the new module, create a function by typing:
Function WhateverYouWantToCallIt()
Access adds
End Function

Between the 2 lines, enter:
DoCmd.OpenForm "Form1"
Include the quotes. Replace Form1 with the name of your form.

To call the function from the macro, use the RunCode action. That's the
basics.
Here's a more comprehensive example.
Save the code below into your module.

In your macro, choose the StopMacro action, and put this beside it in the
Condition column (View menu if you don't see a Condition column):
Not FormOpened("Form1")
This will cause the macro to stop if the form did not open; otherwise it
continues to the next line.

For more information about error handling, see:
Error Handling in VBA
at:
http://allenbrowne.com/ser-23a.html

----------code starts-----------
Function FormOpened(strForm As String) As Boolean
On Error GoTo Err_Handler
'Argument: Name of the form to open
'Return: True if the form opened.

DoCmd.OpenForm strForm
FormOpened = True

Exit_Handler:
Exit Function

Err_Handler:
If Err.Number <> 2501 Then
MsgBox "Error " & Err.Number & " - " & Err.Description
End If
Resume Exit_Handler
End Function
----------code ends-----------


Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: kma | last post by:
I am designing an Access 2000 database on a computer running Windows 98. I have one form with several tabs; all of which have sub forms, some with a subform on a subform. For example, on my...
2
by: Mark Reed | last post by:
Hi All, My database has a macro which opens up a table. A text file is then pasted into the table and the then closed manually. Once closed, I then have another macro which runs certain queries to...
5
by: HS Hartkamp | last post by:
Hi all, I am working with fairly large databases (> 500 Mb / < 2,000,000 rexcords), and often need to do action queries on these. I have the feeling that much of the computing power is going...
5
by: Simon Verona | last post by:
I have an installer project for my VB.net application which as a custom action runs a silent installation of a third party software product. This however, generates an error if the application is...
13
by: Matt F | last post by:
I have a deployment project that I'm setting up. I need to perform a different custom action based on whether this is a first time install or an update. Does anyone have any idea if it's possible...
2
by: bobaol | last post by:
Hi, I do a lot of Macros in Access. I do the drag and drop version, I do not do any VB Code. Currently, I use Macros to run all my queries. I want to be able to automatically update the "Comment"...
1
by: priyaka | last post by:
HI ! I have made a form which is containing some condition. such as if ($_POST && condition = true) (!!! Open action file !!!) else echo...
7
by: MLH | last post by:
If I'm using the following in a procedure... DoCmd.GoToRecord acDataForm, "FormName", acNext, 4 .... how can I recognize the EOF condition? Using GoToRecord, I find myself lost when trying to...
7
jinalpatel
by: jinalpatel | last post by:
I have a report which is based on a macro. Macro is serieas of open queries and a single open report query. When I run this report from my switchboard form it gives me the following series of errors....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.