Goto.Control xxx in a header on a form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I am using the following code from a menu but can not get to the control
object
named Fortryd. Any suggestions?

On Error Resume Next
DoCmd.SelectObject acForm, "Klient", True
DoCmd.GoToControl (FORTRYD)
SendKeys ("{ENTER}")

Thank you.

Regards,
Flemming
 
Flemming said:
Hi,

I am using the following code from a menu but can not get to the control
object
named Fortryd. Any suggestions?

On Error Resume Next
DoCmd.SelectObject acForm, "Klient", True
DoCmd.GoToControl (FORTRYD)
SendKeys ("{ENTER}")

Thank you.

Regards,
Flemming

If I were you I would consider using the SetFocus method to do this, but as
far as the above code is concerned, the control name needs to be quoted i.e.

DoCmd.GoToControl ("FORTRYD")
 
Assuming the form is already open, try:
Forms("Klient").SetFocus
Forms("Klient").ForTryD.SetFocus

Not sure what the SendKeys is aiming to do, but best to avoid it if at all
possible. Stuffing characters in the keyboard buffer is the least reliable
approach, and there is an associated bug where it affects the NumLock light.
 
Thanks. The form is open in Modal.

From the menu I am activating the existing code behind the form
from the buttoms on the form.

That why I use the send keys.

However the suggestions do not get the focus to the buttom.

Any idea's

Flemming


"Allen Browne" skrev:
 
Hi Allen,

Forms("Klient").ForTryD.SetFocus worked well.

Many thanks.

Flemming

"Allen Browne" skrev:
 
Flemming said:
Thanks. The form is open in Modal.

From the menu I am activating the existing code behind the form
from the buttoms on the form.

That why I use the send keys.

However the suggestions do not get the focus to the buttom.

Any idea's

Flemming

I don't know why the SetFocus isn't working (there is obviously something
else going on that you haven't made clear yet) but if all you are trying to
do is to execute the code in the button's Click event procedure, then there
is no need to mess around with the focus or with SendKeys (ugh!). You
could, for example, make the code a method of the form. So, supposing this
is what you have at the moment:

Private Sub Fortryd_Click()

[Some code that does something]

End Sub

You could instead do this:

Public Sub MyMethod()

[Some code that does something]

End Sub
Private Sub Fortryd_Click()

MyMethod

End Sub

And, from your menu, you simply call the method, thus:

Forms!Klient.MyMethod
 
Back
Top