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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing control properties from VBA editor whilst working with SQL 1

Status
Not open for further replies.

rickyoswaldiow

Programmer
Jul 16, 2007
127
GB
Evening all. I am trying to acomplish somthing very simple but my program is falling over:
Code:
    With rsCustomers
        If Not .EOF And Not .BOF Then
            Me.txtCustomerID.Text = !CustomerID
            Me.txtFirstName.Text = ![First Name]
            Me.txtSurname.Text = ![Last Name]
            Me.txtTelephone.Text = !Phone
            Me.txtEmail.Text = !Email
        End If
    End With

My error message is:
You can't reference a property or method of a control unless the control has the focus.

The form that these controls occupy should have focus, since the code is called up from another control on the same form and there is no reference to any other forms. I have also tried to .setfocus but this gives me the error:
Fundamental Microsoft Jet SQL for Access 2000 can't move the focus to the control txtCustomerID
 
Just drop the .Text from your code and it should work. The default property is the .Value property and the control does not need the focus to reference this property. That is not the case with the .Text property.

HTH RuralGuy (RG for short) acXP winXP Pro
Please respond to this forum so all may benefit
 
Interesting, this is a different concept to VB6 where you can specify the .text, is this right?
 
That is correct. VBA is different than VB. You can still specify the .Text property but the control needs to have the focus.

HTH RuralGuy (RG for short) acXP winXP Pro
Please respond to this forum so all may benefit
 
In fact I don't think this is a difference between VBA vs VB6 but Access controls vs UserForm controls.
 
You are welcome. Glad I could help.

HTH RuralGuy (RG for short) acXP winXP Pro
Please respond to this forum so all may benefit
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top