Yodelayheewho
Member
Hello!
I have a list of products and each is aligned to an SCode.
Combo Box = cboSCode (list of product types, ex: Meter, Read, Beta, etc.)
Textbox = txtSCode (code for each product type, ex: S-13-5, S-13-15, S-13-16, etc.)
I set the combo box with a default value: "Select product type to get S-Code"
The textbox is disabled. The user selects the product type from the combo box, which populates the textbox with the corresponding product type code. Works great!
The issue: If the userform is saved, closed then reopened, the combo box value reverts back to the default value instead of showing the product type. However, the value of the textbox (product type code) is correct. How can I get the combo box value to appear correctly if the textbox is not blank?
Here is the code that's working fine.
I tried adding the following code to Initialize with no luck.
I would greatly appreciate your help.
I have a list of products and each is aligned to an SCode.
Combo Box = cboSCode (list of product types, ex: Meter, Read, Beta, etc.)
Textbox = txtSCode (code for each product type, ex: S-13-5, S-13-15, S-13-16, etc.)
I set the combo box with a default value: "Select product type to get S-Code"
The textbox is disabled. The user selects the product type from the combo box, which populates the textbox with the corresponding product type code. Works great!
The issue: If the userform is saved, closed then reopened, the combo box value reverts back to the default value instead of showing the product type. However, the value of the textbox (product type code) is correct. How can I get the combo box value to appear correctly if the textbox is not blank?
Here is the code that's working fine.
Code:
Private Sub UserForm_Initialize()
cboSCode.List=Sheets("SCODE").Range("A2:A10") '1 of 3 codes
'Populate txtSCode based on cboSCode selection '2 of 3 codes
Private Sub cboSCode_Click()
Me.txtSCode.Value = Sheets("SCODE").Range("B" & Me.cboSCode.ListIndex + 2).Value
End Sub
'Populate txtSCode using typing search in cboSCode '3 of 3 codes
Private Sub cboSCode_Change()
Me.txtSCode.Value = Sheets("SCODE").Range("B" & Me.cboSCode.ListIndex + 2).Value
End Sub
I tried adding the following code to Initialize with no luck.
Code:
If txtSCode <>"" Then Sheets("SCODE").Range("B" & me.cboSCode.ListIndex+2).Value = me.txtSCode
I would greatly appreciate your help.