PDA

View Full Version : Cannot reference an object without focus



morton
08-02-2010, 02:15 PM
I have a combo box on a form with all the values listed and some checkboxes below it and some textboxes with numerical values inside to multiply and a button to execute, this is the code im trying to get working upon clicking a button:

If Combo160.SelText = "Granite, (20mm)" And chk7.Enabled = True Then
Me.textout1 = Me.textout1 * Me.ss1
End If
I keep getting error 2185
"You can't reference a property or method for a control unless the control has focus"

i imagine to solve it i will have to use the .setfocus command but am totally stuck have been at it for hours now if anyone could help would be greatly appreciated, the strange thing is that if i do this for example:

If Combo160.Enabled Then
Me.textout1 = Me.Text21.Value * Me.Text22.Value / 1000000
Me.textout2 = Me.Text23.Value * Me.Text24.Value / 1000000
Me.textout3 = Me.Text25.Value * Me.Text26.Value / 1000000
Me.textout4 = Me.Text27.Value * Me.Text28.Value / 1000000
Me.textout5 = Me.Text29.Value * Me.Text30.Value / 1000000
Me.textout6 = Me.Text31.Value * Me.Text32.Value / 1000000
Me.textout7 = Me.Text33.Value * Me.Text34.Value / 1000000
Me.textout8 = Me.Text35.Value * Me.Text36.Value / 1000000
Me.textout9 = Me.Text37.Value * Me.Text38.Value / 1000000
Me.textout10 = Me.Text39.Value * Me.Text40.Value / 1000000

Me.textout11 = Me.Text41.Value * Me.Text42.Value / 1000000
Me.textout12 = Me.Text43.Value * Me.Text44.Value / 1000000
Me.textout13 = Me.Text45.Value * Me.Text46.Value / 1000000
Me.textout14 = Me.Text47.Value * Me.Text48.Value / 1000000
Me.textout15 = Me.Text49.Value * Me.Text50.Value / 1000000
End If

that works and if i do the checkboxes only that works too:

If chk7.Enabled Then
Me.textout1 = Me.textout1 * Me.ss1
End If

Can't see where im going wrong hope someone can help :)


SOLVED: worked it out before the line of code:

"combo160.setfocus"

If Combo160.SelText = "Granite, (20mm)" And chk7.Enabled = True Then
Me.textout1 = Me.textout1 * Me.ss1
End If
thanks anyway :)

HiTechCoach
08-03-2010, 03:43 PM
I have a combo box on a form with all the values listed and some checkboxes below it and some textboxes with numerical values inside to multiply and a button to execute, this is the code im trying to get working upon clicking a button:

If Combo160.SelText = "Granite, (20mm)" And chk7.Enabled = True Then
Me.textout1 = Me.textout1 * Me.ss1
End If

I keep getting error 2185
"You can't reference a property or method for a control unless the control has focus"

i imagine to solve it i will have to use the .setfocus command but am totally stuck have been at it for hours now if anyone could help would be greatly appreciated, the strange thing is that if i do this for example:

If Combo160.Enabled Then
Me.textout1 = Me.Text21.Value * Me.Text22.Value / 1000000
Me.textout2 = Me.Text23.Value * Me.Text24.Value / 1000000
Me.textout3 = Me.Text25.Value * Me.Text26.Value / 1000000
Me.textout4 = Me.Text27.Value * Me.Text28.Value / 1000000
Me.textout5 = Me.Text29.Value * Me.Text30.Value / 1000000
Me.textout6 = Me.Text31.Value * Me.Text32.Value / 1000000
Me.textout7 = Me.Text33.Value * Me.Text34.Value / 1000000
Me.textout8 = Me.Text35.Value * Me.Text36.Value / 1000000
Me.textout9 = Me.Text37.Value * Me.Text38.Value / 1000000
Me.textout10 = Me.Text39.Value * Me.Text40.Value / 1000000

Me.textout11 = Me.Text41.Value * Me.Text42.Value / 1000000
Me.textout12 = Me.Text43.Value * Me.Text44.Value / 1000000
Me.textout13 = Me.Text45.Value * Me.Text46.Value / 1000000
Me.textout14 = Me.Text47.Value * Me.Text48.Value / 1000000
Me.textout15 = Me.Text49.Value * Me.Text50.Value / 1000000
End If

that works and if i do the checkboxes only that works too:

If chk7.Enabled Then
Me.textout1 = Me.textout1 * Me.ss1
End If

Can't see where im going wrong hope someone can help :)


SOLVED: worked it out before the line of code:

"combo160.setfocus"

If Combo160.SelText = "Granite, (20mm)" And chk7.Enabled = True Then
Me.textout1 = Me.textout1 * Me.ss1
End If

thanks anyway :)
I think the problem was the .SelText

I would use this:




If Me.Combo160 = "Granite, (20mm)" And Me.chk7.Enabled = True Then
Me.textout1 = Me.textout1 * Me.ss1
End If