Focus error

alfred67

Registered User.
Local time
Today, 17:42
Joined
Jan 26, 2010
Messages
65
I have the following code gives me this error "you can't reference a property ormethod for the control unless the control has the focus

Private Sub Payment_Quantity_Change()
' Get the first digit of the value in the combo box
Dim firstNumber As String
firstNumber = Left(Me.Parent.Combo4.Text, 1)
' Set the account number combo box
On Error Resume Next
Combo21.Value = CInt(firstNumber)
Me.Parent.Combo4.SetFocus
End Sub

How do I fix this??

Alfred67
 
So the reference here:

firstNumber = Left(Me.Parent.Combo4.Text, 1)

means that you can't use the .TEXT part without that combo4 having the focus. If you are on a different combo's on change event, which it looks like you are, then you don't need the .Text after it. just use Me.Parent.Combo4
 
Hello
Thank you for the quick relpy but now my combo box 21 is not populating which is on my subform any ideas??

Private Sub Payment_Quantity_Change()
' Get the first digit of the value in the combo box
Dim firstNumber As String
firstNumber = Left(Me.Parent.Combo4, 1)
' Set the account number combo box
On Error Resume Next
Combo21.Value = CInt(firstNumber)
End Sub

Thanks
Alfred67
 
Sorry for the multiple questions but it is the only way to narrow it down.

What is the RowSource for the Combo21? By the way you should really rename your objects to meaningful names so nobody is left wondering what you are referring to. Combo21 is not a good name. cboEmployeeName would be a good name (if you had a combo for employees).
 
The rowsource is SELECT Accounts.Accountid, Accounts.Accountname FROM Accounts;

I will try and give you some background of what I'm trying to do. Please keep in mind, I don't know vba code very well .

The user will pick an item number on main form then will fill out the subform for payment. One of the boxes on the subform(combo21) an account has to be picked. Now with some item number ranges for example 200 to 299 Account sec 200 Watermain must be picked.

With that said I'm trying to get it to automactally fill out the Account box(combo21)

So my think is every time the payment Quanitity is fill-in have it automactally fill in

See screen shot

Alfred67
 

Attachments

Hello

I think I have got some of it solved

' Get the first digit of the value in the combo box

Dim firstNumber As String
firstNumber = Left(Me.Parent.Combo4.Column(1), 1)

' Set the account number combo box
Combo21 = CInt(firstNumber)

MsgBox "Combo21=" & Combo21
End Sub

Question : How do I tell Combo21 that Accountid = FirstNumber?? then do I have to use a requery setting??

Alfred67
 
I got it to work

Thank you all the help

Alfred67
 

Users who are viewing this thread

Back
Top Bottom