none
Word 2010 ComboBox issue RRS feed

  • Question

  • I am having a problem with a ComboBox in my user form. When I open my document and edit it using the userform for the first time everything works fine. Part of the UserForm I have a ComboBox that depending on which selection is picked and second userform is opened so I can pick the information that goes with the ComboBox choice and loads it into a text box. When I try to edit the document a second time the secondary UserForm opens automatically before the main UserForm. How can I keep this from happening? Here are my UserForm_Initialize and ComboBox Macros:

    Private Sub UserForm_Initialize()

    Dim MyDate

    Dim myArray, oRoot, sDomain, oSysInfo, sDistinguishedName, _

        oUser, oFirst, oInt, oLast, oName, myArray1, myArray2, myArray3

    myArray = Split("|LOW|MEDIUM|HIGH", "|")

    With CmdRiskWC1

      .List = myArray

      .ListIndex = 0

    End With

    myArray1 = Split("|LOW|MEDIUM|HIGH", "|")

    With CmdRiskWC

      .List = myArray1

      .ListIndex = 0

    End With

    myArray2 = Split("|Any Mode|Modes 1 ,2, or 3|Mode 4/5|Mode 1 reduced power {See Comments}|" _

              & "Mode 1|Mode 2|Mode 3|Mode 4|Mode 5|", "|")

    With CmdMode

      .List = myArray2

      .ListIndex = 0

    End With

    myArray3 = Split("|Green|Yellow|Orange|Red", "|")

    With CmdPRisk

      .List = myArray3

      .ListIndex = 0

    End With

    MyDate = Date

    On Error Resume Next

    Set oFF = ActiveDocument.FormFields

    Set oBMs = ActiveDocument.Bookmarks

    Set oRoot = GetObject("LDAP://RootDSE")

        sDomain = oRoot.Get("DefaultNamingContext")

    Set oSysInfo = CreateObject("ADSystemInfo")

        sDistinguishedName = oSysInfo.UserName

    Set oUser = GetObject("LDAP://" & sDistinguishedName)

        oFirst = oUser.givenname

        oInt = oUser.initials

        oLast = oUser.sn

    If oInt = "" Then

        oName = (oFirst & " " & oLast)

    Else

        oName = (oFirst & " " & oInt & " " & oLast)

    End If

    WName.Value = oName

    WName.Enabled = False

    WDate.Value = MyDate

    WDate.Enabled = False

    WLCO.Value = oBMs("WLCO").Range.Text

    WLCO1.Value = oBMs("WLCO1").Range.Text

    WOper.Value = oBMs("WOper").Range.Text

    CmdRiskWC.Value = oBMs("NBases").Range.Text

    TextBox1.Value = oBMs("NMitigate").Range.Text

    CmdRiskWC1.Value = oBMs("CBases").Range.Text

    TextBox3.Value = oBMs("CMitigate").Range.Text

    WDetail.Value = oBMs("WDetail").Range.Text

    CmdPRisk.Value = oBMs("PRisk").Range.Text

    Comments.Value = oBMs("WComment").Range.Text

    CmdMode.Value = oBMs("PlantMode").Range.Text

    TextBox5.Value = oBMs("PBases").Range.Text

    lstTextBox1 = oBMs("NMitigate").Range.Text

    lstTextBox2 = oBMs("CMitigate").Range.Text

    TextBox2.Value = oBMs("NBases").Range.Text

    TextBox4.Value = oBMs("CBases").Range.Text

    For i = 1 To 11

      If oBMs("CB" & i).Range.Font.Color = wdColorAutomatic Then

        Me.Controls("Ck" & i).Value = False

      Else

        Me.Controls("Ck" & i).Value = True

      End If

    Next i

    If oBMs("wRev").Range.Text = "" Then

        wRev.Text = ""

    Else

    If oBMs("wRev").Range.Text >= "0" Then

        wRev.Text = ((oBMs("wRev").Range.Text) + 1)

    End If

    End If

    wRev.Enabled = False

    'ActiveDocument.Saved = True

    TextBox2 = ActiveDocument.Variables("RiskLevel1").Value

    On Error Resume Next

    frmWC.lstTextBox1.List = Split(ActiveDocument.Variables("Bases").Value, "|")

    TextBox4 = ActiveDocument.Variables("RiskLevel2").Value

    On Error Resume Next

    frmWC.lstTextBox2.List = Split(ActiveDocument.Variables("Bases1").Value, "|")

    End Sub

    Private Sub CmdRiskWC_Click()

    If CmdRiskWC = "LOW" Then

        TextBox1.Locked = False

        TextBox1 = "All questions on the Risk Assessment Worksheet are 'NO'. Performance of this Work poses LOW risk to Personnel, the Plant, and the Environment."

        lstTextBox1.Clear

        TextBox1.Locked = True

        EditBases.Visible = False

        TextBox2 = CmdRiskWC

    End If

    If CmdRiskWC = "MEDIUM" Then

        EditBases.Visible = True

    End If

    If CmdRiskWC = "HIGH" Then

        EditBases.Visible = True

    End If

    If CmdRiskWC = "MEDIUM" And wRev = "" Then

        TextBox1.Locked = False

        TextBox1 = ""

        lstTextBox1.Clear

        UserForm1.Show

        TextBox1.Locked = True

        TextBox2 = CmdRiskWC

    End If

    If CmdRiskWC = "HIGH" And wRev = "" Then

        TextBox1.Locked = False

        TextBox1 = ""

        lstTextBox1.Clear

        UserForm1.Show

        TextBox1.Locked = True

        TextBox2 = CmdRiskWC

    End If

    If CmdRiskWC = "MEDIUM" And TextBox2 = "LOW" Then

        TextBox1 = ""

        lstTextBox1.Clear

        UserForm1.Show

        TextBox2 = CmdRiskWC

        EditBases.Visible = True

    End If

    If CmdRiskWC = "HIGH" And TextBox2 = "LOW" Then

        TextBox1 = ""

        lstTextBox1.Clear

        UserForm1.Show

        TextBox2 = CmdRiskWC

        EditBases.Visible = True

    End If

    If CmdRiskWC = "LOW" And TextBox2 = "MEDIUM" Then

        TextBox1 = "All questions on the Risk Assessment Worksheet are 'NO'. Performance of this Work poses LOW risk to Personnel, the Plant, and the Environment."

        lstTextBox1.Clear

        TextBox2 = "LOW"

    End If

    If CmdRiskWC = "LOW" And TextBox2 = "HIGH" Then

        TextBox1 = "All questions on the Risk Assessment Worksheet are 'NO'. Performance of this Work poses LOW risk to Personnel, the Plant, and the Environment."

        lstTextBox1.Clear

        TextBox2 = "LOW"

    End If

    If CmdRiskWC = "MEDIUM" And TextBox2 = "HIGH" Then

        TextBox1 = ""

        lstTextBox1.Clear

        UserForm2.Show

        TextBox2 = CmdRiskWC

    End If

    If CmdRiskWC = "HIGH" And TextBox2 = "MEDIUM" Then

        TextBox1 = ""

        lstTextBox1.Clear

        UserForm1.Show

        TextBox2 = CmdRiskWC

    End If

    End Sub


    • Edited by fuzzhead58 Saturday, September 6, 2014 1:38 PM
    Saturday, September 6, 2014 1:36 PM

Answers

All replies

  • This is the sort of issue that tends to occur when you are processing the userform within the userform code rather than in the calling macro, and probably never unloading the form so values are retained that are going to affect what happens next.

    However it is difficult to get a feel for the process, without access to the document containing the form. Can you make that available e.g. via dropbox or onedrive ?


    Graham Mayor - Word MVP
    www.gmayor.com

    Sunday, September 7, 2014 9:32 AM
  • I figured out my problem. It was in my Rev numbering. It works fine now.
    • Marked as answer by fuzzhead58 Tuesday, September 9, 2014 5:30 AM
    Tuesday, September 9, 2014 5:22 AM