Connecting Tech Pros Worldwide Forums | Help | Site Map

How does this work?

John
Guest
 
Posts: n/a
#1: Jun 22 '07
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



ARC
Guest
 
Posts: n/a
#2: Jun 22 '07

re: How does this work?


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:f5hjfg$17ck$1@textnews.wanadoo.nl...
Quote:
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
>

John
Guest
 
Posts: n/a
#3: Jun 23 '07

re: How does this work?


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" <andy@andyc.comschreef in bericht
news:EoYei.21468$C96.4280@newssvr23.news.prodigy.n et...
Quote:
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:f5hjfg$17ck$1@textnews.wanadoo.nl...
Quote:
>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
>>
>
>

Marshall Barton
Guest
 
Posts: n/a
#4: Jun 23 '07

re: How does this work?


John wrote:
Quote:
>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
ARC
Guest
 
Posts: n/a
#5: Jun 23 '07

re: How does this work?


How about this?

forms(strMyString).Name.setfocus






"John" <jo@hn.comwrote in message
news:f5hn2t$18kg$1@textnews.wanadoo.nl...
Quote:
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" <andy@andyc.comschreef in bericht
news:EoYei.21468$C96.4280@newssvr23.news.prodigy.n et...
Quote:
>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:f5hjfg$17ck$1@textnews.wanadoo.nl...
Quote:
>>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
>>>
>>
>>
>
>

ARC
Guest
 
Posts: n/a
#6: Jun 23 '07

re: How does this work?


Actually, I think the last post won't work. Here's another to try:


Forms(StrMyString).Form.setfocus



"ARC" <andy@andyc.comwrote in message
news:pbcfi.6861$c06.4346@newssvr22.news.prodigy.ne t...
Quote:
How about this?
>
forms(strMyString).Name.setfocus
>
>
>
>
>
>
"John" <jo@hn.comwrote in message
news:f5hn2t$18kg$1@textnews.wanadoo.nl...
Quote:
>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" <andy@andyc.comschreef in bericht
>news:EoYei.21468$C96.4280@newssvr23.news.prodigy. net...
Quote:
>>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:f5hjfg$17ck$1@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
>>>>
>>>
>>>
>>
>>
>
>

John
Guest
 
Posts: n/a
#7: Jun 23 '07

re: How does this work?


Thanks. I got it working.
john

"ARC" <andy@andyc.comschreef in bericht
news:Hmcfi.6864$c06.1830@newssvr22.news.prodigy.ne t...
Quote:
Actually, I think the last post won't work. Here's another to try:
>
>
Forms(StrMyString).Form.setfocus
>
>
>
"ARC" <andy@andyc.comwrote in message
news:pbcfi.6861$c06.4346@newssvr22.news.prodigy.ne t...
Quote:
>How about this?
>>
>forms(strMyString).Name.setfocus
>>
>>
>>
>>
>>
>>
>"John" <jo@hn.comwrote in message
>news:f5hn2t$18kg$1@textnews.wanadoo.nl...
Quote:
>>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" <andy@andyc.comschreef in bericht
>>news:EoYei.21468$C96.4280@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:f5hjfg$17ck$1@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
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>

Closed Thread


Similar Microsoft Access / VBA bytes