Consulting

Results 1 to 2 of 2

Thread: Cannot reference an object without focus

  1. #1
    VBAX Newbie
    Joined
    Aug 2010
    Posts
    1
    Location

    Cannot reference an object without focus

    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:

    [vba]If Combo160.SelText = "Granite, (20mm)" And chk7.Enabled = True Then
    Me.textout1 = Me.textout1 * Me.ss1
    End If[/vba]
    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:

    [vba]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[/vba]

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

    [vba]If chk7.Enabled Then
    Me.textout1 = Me.textout1 * Me.ss1
    End If[/vba]

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


    SOLVED: worked it out before the line of code:

    "combo160.setfocus"

    [vba]If Combo160.SelText = "Granite, (20mm)" And chk7.Enabled = True Then
    Me.textout1 = Me.textout1 * Me.ss1
    End If
    [/vba] thanks anyway
    Last edited by morton; 08-03-2010 at 08:46 AM.

  2. #2
    Quote Originally Posted by morton
    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
    Boyd Trimmell aka HiTechCoach
    Microsoft Access MVP -2010-2015

    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •