Execute macro under certain conditions?

Franky G

Registered User.
Local time
Today, 11:53
Joined
Feb 6, 2001
Messages
62
Hi,

I nearly have this, but not quite!
Using a form to input text, from which a report will run using the text as part of a search.

I want the report to run,
1) When the command button is pressed,or,
2) When the user hits <CR>

Don't want it to run if any other key is pressed, such as TAB.

Any thoughts?
Should I be using the 'On Change' or 'on key down' properties?

Also, I don't want it to run if no text has been typed. I have tried creating a validation rule for the text field <>NULL, with an appropriate message but this does nothing!

Any help appreciated,

Frank G
 
Try checking the length of the text field, not whether it's null:
If len(txtField) = 0 then 'nothing there

Are you doing this in the "after update" now, or when???
 
Personally, I would just give the user a button to click and run the macro on that; also if you put this code (or something similar) into the OnClick event of the button, then the macro will only run if there's something in the textbox.

If Not (IsNull(Me.Text9)) Then
DoCmd.RunMacro ("MyMacroname")
Else
MsgBox "Please enter some text first"
End If

It's difficult to get the same sort of thing to happen when CR is pressed as Access already expects to do something (add a row or move to the next field) - as you've discovered.. you could set the tab order so that the command button is after the text box, but the user will have to press CR twice to execute the search (once to leave the text box and again to activate the button) - it's not so convenient, but it is more consistent with Windows protocols.

HTH

Mike

[This message has been edited by Mike Gurman (edited 02-06-2001).]
 
Thanks, it's working the way I want now.

FrankY
 

Users who are viewing this thread

Back
Top Bottom