control focus

W

wraithzshadow

so here is what im doing... ive got two forms, form1 opens form2 and
moves a bunch of textboxes around on form2... it sets the onGotFocus
property to call a macro... this works, but im not sure if its the best
way to do it, i did it this way because programatically adding
procedures to each button sounds difficult
what im trying to achieve is this... whenever any textbox recieves
focus, it changes the properties of a couple of buttons (i.e. location,
visibility), then sets a global string to its own name. if the buttons
get pressed the button will call a function to make changes to the form
based on the value of the global string which has the name of the
textbox. the function the buttons call will move textboxes around,
after the textboxes have been moved, the focus needs to shift to
another textbox (and when that textbox recieves focus it moves the
buttons, changes the global string etc...)
i was able to programatically set the onGotFocus property to call a
macro, the macro calls a function, and that function tries to cycle
through all of the controls checking the containsFocus property to
determine which textbox has focus...

For Each ctl In Me.Controls
If ctl.containsFocus Then
MsgBox ctl.Name & " has the focus right now!"
End If
Next

when it gets to "If ctl.containsFocus Then"
it gives me an error saying "object doesnt support this property or
method
the macro fails as a result

so i really dont want to use macros to begin with, but im not certain
how else to go about it... i would appreciate suggestions on how to
determine which control has focus, as well as suggestions on ways
around the ridiculous onGotFocus calling a macro which calls a focus
etc... any suggestions really. thanks in advance... Donald
 
G

Guest

It is much simpler than that

Dim ctlCurr As Control

Set ctlCurr = Screen.ActiveControl
MsgBox = "The Control with the Focus is " & ctlCurr.Name
 

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

Top