Consulting

Results 1 to 6 of 6

Thread: Need to change value of checkbox from userform

  1. #1
    VBAX Regular
    Joined
    Nov 2020
    Posts
    16
    Location

    Need to change value of checkbox from userform

    I have a userform where i want checkboxes from a worddocument to be controlled from a userform. But i feel stupid since i can´t even find out the names of the checkboxes from the worddocument.
    They have been added from the developertab and are active x controls type checkbox. I can check the properties of the checkbox from the developertab but the name of the checkbox is nowhere to be found.

    Edit
    My bad, figured it out; had selected the wrong kind of checkbox...
    Last edited by magsol76; 12-03-2020 at 08:09 AM.

  2. #2
    ActiveX check boxes are best avoided. I don't know what you settled on, but the best choice would be content controls which are simple enough to process.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Regular
    Joined
    Nov 2020
    Posts
    16
    Location
    It seems i have used checkbox content controls all over the document so if i could get them to work the better.
    How would i go about doing it? I have 2 checkboxes to start with that I have given the tag CC_ja and CC_nej respectively.

    The If-statement that controls the checkboxes is:

    Private Sub Generera_Click()

    If ActiveDocument.Bookmarks.Exists("bookmarkname") = False Then
    ???CC_ja.Checked = True
    ???CC_nej.Checked = False
    Else
    ???CC_ja.Checked = False
    ???CC_nej.Checked = True
    End If

    End Sub

    I have no clue what i should write to use CC_ja and CC_nej from the active document as I have never called content controls from a userform.

  4. #4
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,335
    Location
    ActiveDocument.SelectConentControlsByTitle("???CC_ja").Item(1).Checked = True
    ActiveDocument.SelectConentControlsByTitle("???CC_nea").Item(1).Checked = False
    Greg

    Visit my website: http://gregmaxey.com

  5. #5
    VBAX Regular
    Joined
    Nov 2020
    Posts
    16
    Location
    I tried this code (tried another if-statement) but it can´t find the contentcontrol. I get error 5941.
    PS. I use tags instead of title.

    If UserForm1.OB_Fastighetsägare_Ja.Value = True And (UserForm1.OB_Verksamhet_Företag.Value = True Or UserForm1.OB_Verksamhet_Lantbruk.Value = True) Then
    ActiveDocument.SelectContentControlsByTag("CC_ja.Value").Item(1).Checked = True
    ActiveDocument.SelectContentControlsByTag("CC_nej.Value").Item(1).Checked = False
    End If

  6. #6
    VBAX Regular
    Joined
    Nov 2020
    Posts
    16
    Location
    Found the fault with the .Value from the previous code. This is my new code and it works fine:

    If UserForm1.OB_Fastighetsägare_Ja.Value = True And (UserForm1.OB_Verksamhet_Företag.Value = True Or UserForm1.OB_Verksamhet_Lantbruk.Value = True) Then
    ActiveDocument.SelectContentControlsByTag("CC_ja").Item(1).Checked = True And ActiveDocument.SelectContentControlsByTag("CC_nej").Item(1).Checked = False
    End If

    If UserForm1.OB_Fastighetsägare_Nej.Value = True And (UserForm1.OB_Verksamhet_Företag.Value = True Or UserForm1.OB_Verksamhet_Lantbruk.Value = True) Then
    ActiveDocument.SelectContentControlsByTag("CC_ja").Item(1).Checked = False And ActiveDocument.SelectContentControlsByTag("CC_nej").Item(1).Checked = True
    End If

    If UserForm1.OB_Fastighetsägare_Vetej.Value = True And (UserForm1.OB_Verksamhet_Företag.Value = True Or UserForm1.OB_Verksamhet_Lantbruk.Value = True) Then
    ActiveDocument.SelectContentControlsByTag("CC_ja").Item(1).Checked = False And ActiveDocument.SelectContentControlsByTag("CC_nej").Item(1).Checked = False
    End If

Posting Permissions

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