View Full Version : [SOLVED:] Value to stay visible
Aussiebear
05-23-2015, 04:48 PM
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
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
Aussiebear
05-23-2015, 05:14 PM
hmmm.. why is MyArray(0,1) = .Range("A3").Value repeated?
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 :dunno
cboSelectJobs.Column() = MyArray
Aussiebear
05-23-2015, 07:16 PM
I would like the combobox on a form to maintain its value once selected. Currently it loses its selected value
Aussiebear
05-23-2015, 07:21 PM
Shouldn't this have an index number in the brackets? I :dunno
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.
mikerickson
05-23-2015, 07:28 PM
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
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
Aussiebear
05-23-2015, 10:45 PM
Thanks Mike, yours is working well
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
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.