By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,971 Members | 890 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,971 IT Pros & Developers. It's quick & easy.

How does this work?

P: n/a
Following code belongs to the first field in form B. When I open form B from
form A, ctl.Name returns the name of Form's A button which I just clicked.
How does this work? I thought when the field got focus that would be the
active control. How can I solve it so that it will return the name of the
field the code is in?

Private Sub MyFirstField_GotFocus()

Dim ctl As Control
Set ctl = Screen.ActiveControl
InfoField = ctl.Name

End Sub

Thanks,
john
Jun 22 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
ARC
In the button that opens form b, you might want to put 2 set focus commands:

Forms!formb.setfocus
forms!formb.form![ctrlname].setfocus

"John" <jo@hn.comwrote in message
news:f5***********@textnews.wanadoo.nl...
Following code belongs to the first field in form B. When I open form B
from form A, ctl.Name returns the name of Form's A button which I just
clicked. How does this work? I thought when the field got focus that would
be the active control. How can I solve it so that it will return the name
of the field the code is in?

Private Sub MyFirstField_GotFocus()

Dim ctl As Control
Set ctl = Screen.ActiveControl
InfoField = ctl.Name

End Sub

Thanks,
john

Jun 22 '07 #2

P: n/a
Thanks,

Forms!formb.setfocus works fine.

The problem now is that the name of the form is looked up in a table, so I
have it in a string value. I tried every possible reference without luck:

Forms!strMyString.setfocus
Forms(strMyString).setfocus
Forms![strMyString].setfocus

What am I doing wrong???
john

"ARC" <an**@andyc.comschreef in bericht
news:Eo******************@newssvr23.news.prodigy.n et...
In the button that opens form b, you might want to put 2 set focus
commands:

Forms!formb.setfocus
forms!formb.form![ctrlname].setfocus

"John" <jo@hn.comwrote in message
news:f5***********@textnews.wanadoo.nl...
>Following code belongs to the first field in form B. When I open form B
from form A, ctl.Name returns the name of Form's A button which I just
clicked. How does this work? I thought when the field got focus that
would be the active control. How can I solve it so that it will return
the name of the field the code is in?

Private Sub MyFirstField_GotFocus()

Dim ctl As Control
Set ctl = Screen.ActiveControl
InfoField = ctl.Name

End Sub

Thanks,
john


Jun 22 '07 #3

P: n/a
John wrote:
>Following code belongs to the first field in form B. When I open form B from
form A, ctl.Name returns the name of Form's A button which I just clicked.
How does this work? I thought when the field got focus that would be the
active control. How can I solve it so that it will return the name of the
field the code is in?

Private Sub MyFirstField_GotFocus()

Dim ctl As Control
Set ctl = Screen.ActiveControl
InfoField = ctl.Name

End Sub

That seems a little odd, but I'd rather not trust the Screen
object to know which form is the active form so early in the
transition. Try using Me.ActiveControl

--
Marsh
Jun 23 '07 #4

P: n/a
ARC
How about this?

forms(strMyString).Name.setfocus


"John" <jo@hn.comwrote in message
news:f5***********@textnews.wanadoo.nl...
Thanks,

Forms!formb.setfocus works fine.

The problem now is that the name of the form is looked up in a table, so I
have it in a string value. I tried every possible reference without luck:

Forms!strMyString.setfocus
Forms(strMyString).setfocus
Forms![strMyString].setfocus

What am I doing wrong???
john

"ARC" <an**@andyc.comschreef in bericht
news:Eo******************@newssvr23.news.prodigy.n et...
>In the button that opens form b, you might want to put 2 set focus
commands:

Forms!formb.setfocus
forms!formb.form![ctrlname].setfocus

"John" <jo@hn.comwrote in message
news:f5***********@textnews.wanadoo.nl...
>>Following code belongs to the first field in form B. When I open form B
from form A, ctl.Name returns the name of Form's A button which I just
clicked. How does this work? I thought when the field got focus that
would be the active control. How can I solve it so that it will return
the name of the field the code is in?

Private Sub MyFirstField_GotFocus()

Dim ctl As Control
Set ctl = Screen.ActiveControl
InfoField = ctl.Name

End Sub

Thanks,
john



Jun 23 '07 #5

P: n/a
ARC
Actually, I think the last post won't work. Here's another to try:
Forms(StrMyString).Form.setfocus

"ARC" <an**@andyc.comwrote in message
news:pb*****************@newssvr22.news.prodigy.ne t...
How about this?

forms(strMyString).Name.setfocus


"John" <jo@hn.comwrote in message
news:f5***********@textnews.wanadoo.nl...
>Thanks,

Forms!formb.setfocus works fine.

The problem now is that the name of the form is looked up in a table, so
I have it in a string value. I tried every possible reference without
luck:

Forms!strMyString.setfocus
Forms(strMyString).setfocus
Forms![strMyString].setfocus

What am I doing wrong???
john

"ARC" <an**@andyc.comschreef in bericht
news:Eo******************@newssvr23.news.prodigy. net...
>>In the button that opens form b, you might want to put 2 set focus
commands:

Forms!formb.setfocus
forms!formb.form![ctrlname].setfocus

"John" <jo@hn.comwrote in message
news:f5***********@textnews.wanadoo.nl...
Following code belongs to the first field in form B. When I open form B
from form A, ctl.Name returns the name of Form's A button which I just
clicked. How does this work? I thought when the field got focus that
would be the active control. How can I solve it so that it will return
the name of the field the code is in?

Private Sub MyFirstField_GotFocus()

Dim ctl As Control
Set ctl = Screen.ActiveControl
InfoField = ctl.Name

End Sub

Thanks,
john



Jun 23 '07 #6

P: n/a
Thanks. I got it working.
john

"ARC" <an**@andyc.comschreef in bericht
news:Hm*****************@newssvr22.news.prodigy.ne t...
Actually, I think the last post won't work. Here's another to try:
Forms(StrMyString).Form.setfocus

"ARC" <an**@andyc.comwrote in message
news:pb*****************@newssvr22.news.prodigy.ne t...
>How about this?

forms(strMyString).Name.setfocus


"John" <jo@hn.comwrote in message
news:f5***********@textnews.wanadoo.nl...
>>Thanks,

Forms!formb.setfocus works fine.

The problem now is that the name of the form is looked up in a table, so
I have it in a string value. I tried every possible reference without
luck:

Forms!strMyString.setfocus
Forms(strMyString).setfocus
Forms![strMyString].setfocus

What am I doing wrong???
john

"ARC" <an**@andyc.comschreef in bericht
news:Eo******************@newssvr23.news.prodigy .net...
In the button that opens form b, you might want to put 2 set focus
commands:

Forms!formb.setfocus
forms!formb.form![ctrlname].setfocus

"John" <jo@hn.comwrote in message
news:f5***********@textnews.wanadoo.nl...
Following code belongs to the first field in form B. When I open form
B from form A, ctl.Name returns the name of Form's A button which I
just clicked. How does this work? I thought when the field got focus
that would be the active control. How can I solve it so that it will
return the name of the field the code is in?
>
Private Sub MyFirstField_GotFocus()
>
Dim ctl As Control
Set ctl = Screen.ActiveControl
InfoField = ctl.Name
>
End Sub
>
Thanks,
john
>




Jun 23 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.