Consulting

Results 1 to 10 of 10

Thread: Value to stay visible

  1. #1
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location

    Value to stay visible

    I currently have a combobox which is used to select the job number for the task at hand, but the job number is not retained until changed. How can I make this number be retained?

    Sub cboSelectJobs_Change()
    Dim MyArray(0, 5) As String
    MyArray(0, 0) = Sheets("Work Orders").Range("A2").Value
    MyArray(0, 1) = Worksheets("Work Orders").Range("A3").Value
    MyArray(0, 2) = Worksheets("Work Orders").Range("A4").Value
    MyArray(0, 3) = Worksheets("Work Orders").Range("A5").Value
    MyArray(0, 4) = Worksheets("Work Orders").Range("A6").Value
    cboSelectJobs.Column() = MyArray
    End Sub
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Sub cboSelectJobs_Change() 
       Dim JobNo As String
        Dim MyArray(0, 5) As String 
    With Sheets("Work Orders"
       JobNo = .Range("A2").Value 
        MyArray(0, 1) = .Range("A3").Value
        MyArray(0, 0) = .Range("A2").Value 
        MyArray(0, 1) = .Range("A3").Value 
        MyArray(0, 2) = .Range("A4").Value 
        MyArray(0, 3) = .Range("A5").Value 
        MyArray(0, 4) = .Range("A6").Value 
        cboSelectJobs.Column() = MyArray 
    End With
    End Sub
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    hmmm.. why is MyArray(0,1) = .Range("A3").Value repeated?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Typo?

    Souldn't be, I nevr make tpyos.

    However, I am not real clear what you are asking for. Sorry.
    Shouldn't this have an index number in the brackets? I
    cboSelectJobs.Column() = MyArray
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  5. #5
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    I would like the combobox on a form to maintain its value once selected. Currently it loses its selected value
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  6. #6
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    Shouldn't this have an index number in the brackets? I
    cboSelectJobs.Column() = MyArray
    Don't know, however it currently shows the job numbers that fall within the array. I have been thinking about turning the combobox into a 2 column display, since its possible to possibly get the wrong job number if you don't know which job number is for which client.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  7. #7
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Perhaps this, if you are sure that the current selection is one of the values that is being put in the Combobox's list.
    Sub cboSelectJobs_Change() 
        Dim MyArray(0, 5) As String
        Dim CurrentValue as String
    
        CurrentValue = cboSelectJobs.Value
    
        MyArray(0, 0) = Sheets("Work Orders").Range("A2").Value 
        MyArray(0, 1) = Worksheets("Work Orders").Range("A3").Value 
        MyArray(0, 2) = Worksheets("Work Orders").Range("A4").Value 
        MyArray(0, 3) = Worksheets("Work Orders").Range("A5").Value 
        MyArray(0, 4) = Worksheets("Work Orders").Range("A6").Value 
        cboSelectJobs.Column() = MyArray
        cboSelectJobs.Value = currentValue
    End Sub

  8. #8
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Sub cboSelectJobs_Change()
    I would like the combobox on a form to maintain its value once selected
    But, you are loading the combo box with new (or the same) values when you make a selection. At that point, there is no more selection.

    Sub cboSelectJobs_Change() 
        Dim JobNo As String 
       JobNo = cboSelectJobsValue
    'Do Something with selected JobNo.
    
    End Sub
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  9. #9
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    Thanks Mike, yours is working well
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  10. #10
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    I don't think so.

    What is the content of cboselectJobsvalue before selecting any value in it ?

    It should be:
    Sub Userform_initialize() 
      cboSelectJobs.List=Sheets("Work Orders").Range("A2:A6").Value 
    End Sub
    After this
    Sub cboSelectJobs_Change() is redundant

Posting Permissions

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