How to Cancel a halt popup

  • Thread starter Thread starter Colin Hayes
  • Start date Start date
C

Colin Hayes

Hi All

I have a query which runs a popup box , using this line in the query
itself

Like [Filter By Which Number?]

I run this via a sendkeys macro through F10.

When I run it , the box comes up and finds the number I need when I fill
it in. However , if I cancel the box I get a 'Halt' box.

Is it possible to avoid this extra halt box , so If I cancel the query ,
it just disappears?

Grateful for any help.
 
Hi All

I have a query which runs a popup box , using this line in the query
itself

Like [Filter By Which Number?]

I run this via a sendkeys macro through F10.

When I run it , the box comes up and finds the number I need when I fill
it in. However , if I cancel the box I get a 'Halt' box.

Is it possible to avoid this extra halt box , so If I cancel the query ,
it just disappears?

Grateful for any help.

1) The Like keyword is used with a wild card, i.e.
Like [What name?] & "*"
to return all names in the column that begin with whatever text has
been entered.

If you are not using a wild card, just use, as query criteria,
[Filter By Which Number?].

2) The big drawback in using macros is that there is no error
handling available. Cancelling the query causes and error.

3) Use Code instead.
From whatever event on the form you are using to open the query,
write:
[Enter Procedure]
on that event line. Then click on the little button with the 3 dots
that appears on that line.
When the code window opens the cursor will be flashing between 2
already existing lines of code. Between those lines, write:

On Error Goto Err_Handler
DoCmd.OpenQuery "QueryName"

Exit_Sub:
Exit Sub
Err_Handler:
If Err = 2001 then
Else
MsgBox "Error#: " & Err.Number & ' " & Err.Description
end if
Resume Exit_Sub

Change "QueryName" to whatever tha actual name of your query is.

If you cancel the query prompt there will be no error message.
 
1) The Like keyword is used with a wild card, i.e.
Like [What name?] & "*"
to return all names in the column that begin with whatever text has
been entered.

If you are not using a wild card, just use, as query criteria,
[Filter By Which Number?].

2) The big drawback in using macros is that there is no error
handling available. Cancelling the query causes and error.

3) Use Code instead.
From whatever event on the form you are using to open the query,
write:
[Enter Procedure]
on that event line. Then click on the little button with the 3 dots
that appears on that line.
When the code window opens the cursor will be flashing between 2
already existing lines of code. Between those lines, write:

On Error Goto Err_Handler
DoCmd.OpenQuery "QueryName"

Exit_Sub:
Exit Sub
Err_Handler:
If Err = 2001 then
Else
MsgBox "Error#: " & Err.Number & ' " & Err.Description
end if
Resume Exit_Sub

Change "QueryName" to whatever tha actual name of your query is.

If you cancel the query prompt there will be no error message.

Hi Fred

OK thanks for that - I'll give it a go.


^_^
 
Colin,

In addition to Fred's comments, you might want to consider using a form to
initiate your query, rather than using a parameter in the query itself. I
will frequently create small pop-up forms (actually have a little template
for this) that is about the size of a standard message box dialog. In that
form, I put a label that describes the values to enter, and provide OK and
Cancel buttons. I also have text or combo boxes for user input to the query.
Then, in the query, rather than using the parameter [Filter by which
number], I use Forms!FormName.txt_number.

If I click the cancel button, the form closes, and the query never runs.

If I hit the OK button, I test to make sure that the value in txt_number is
within any constraints, and that is actually of the correct data type. If it
isn't, I display a warning and set the focus back to the text box. If it is
OK, then I run the query.

The advantages of this technique are that:
1. it give you the ability to cancel the query
2. it provides error checking of the value you enter.


HTH
Dale
 

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

Back
Top