On Got Focus Event Procedure

RichO

Registered Yoozer
Local time
Today, 02:33
Joined
Jan 14, 2004
Messages
1,036
Two questions:

First, I want a report to run using a command button's On Click or On Got Focus. How do I get both of these options to point to the same Event Procedure?

Second, when I run this report from the On Got Focus, as soon as I close the report it runs again immediately because the button has not lost focus. How do you fix this?

Thanks.
 
Procedures attached to command buttons usually have this type of structure:
Code:
Private Sub cmdButtonName_Click()
'code in here
End Sub
If you want to run the same code that gets called when someone clicks the "cmdButtonName" command button, just place:
cmdButtonName_Click
in the procedure that you're calling from.

So for example:
Code:
Private Sub cmdButtonName_GotFocus()
    cmdButtonName_Click
End Sub
Second, when I run this report from the On Got Focus, as soon as I close the report it runs again immediately because the button has not lost focus. How do you fix this?
Well, first I wouldn't run code from a command button this way, but if you must...what happens is when the report loses the focus, the focus returns back to the calling form and guess where the focus needs to go - to a control on that form. It goes right back to the command button. You'll have to put some code into the report's close event to change the focus to another control on the form.
 
Actually, that would be ideal because when I close the report, I want the focus to go back to the text box for inputting data.

I'm in the process of learning VBA so I wouldn't know how to go about this. What type of code would I have to put in the report's On Close event to change the focus to the input box on the form? The form has just a text box and a command button.

Is it pretty simple?

Thanks for the help.
 
Here's some sample code. Place this line:
Forms("formname").Controls("textboxname").SetFocus
just before the line of code in your report that closes the report. If you have no code that closes the report, just put it into the report's close event.
 

Users who are viewing this thread

Back
Top Bottom