Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

referencing a control without focus

Status
Not open for further replies.

laquer09

MIS
Mar 14, 2003
10
Hi, I'm not really used to programming in VBA, although I have some experience with VB. I'm really annoyed at the fact that you can not reference a control in Access without it's having the focus. First of all, this doesn't logically make sense to me. Second of all, I can't figure out how to use a command button because by virtue of pressing the button, it has the focus. I truly appreciate your help. Thank you
 
1) You can access a control regardless of it's focus status.

e.g. Forms("FormName")("ControlName") or Forms![FormName]![ControlName] or Me.ControlName.

2) to determine which object has focus, you can use:
Screen.ActiveControl
or
Screen.ActiveForm

3) if you want to find out what had the focus before pushing a command button, use Screen.PreviousControl.
 
Ok, here is the code that I am using

Private Sub Form_Load()

Me.ItemNumber.text = Forms![Find Item]![Text84].text

End Sub

and here is the error I am getting

"You can't reference a property or method for a control unless the control has the focus."
 
Change your code to:

Private Sub Form_Load()

Me.ItemNumber= Forms![Find Item]![Text84]

End Sub

When you explicitly reference the .text propoerty, Access yells at you and says you have to set the focus first. The .text proprerty is the default field of the text box.


Tyrone Lumley
augerinn@gte.net


 
Try this
Me.ItemNumber.value = Forms![Find Item]![Text84].text
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top