Update a combo box

NDMDRB

Board Regular
Joined
Jun 20, 2016
Messages
164
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I have the following code on my userform "frmPOS" to check if any entered client name if exist or not, if so, get the ID and mobile to txtID and txtMobile
If not, pop up msg that this is not exist and if I need to add a new client, if so, show the form "frmNewClient" and add new client

This code works very well, but what I need, once I add a new client after the above procedure, get back to the main form with updated clients list (cmbName to updated with the new client name)

I've tried to unload the form and reopen it but non of the codes works well, (The notes included in the code is what I've tried)
and I tried to put "frmPOS.show" after I add a new client but getting the same result, non of the codes works well


Code:
Dim UfDic As Object

Private Sub cmbName_Change()   With Me.cmbName
      If UfDic.exists(.Value) Then
         Me.txtID.Value = UfDic.Item(.Value)(0)
         Me.txtMobile.Value = UfDic.Item(.Value)(1)
      Else
         If MsgBox(.Value & "!!!" & vbCrLf & vbCrLf & "The above client name is not Exist" & vbCrLf & vbCrLf & _
         "Do you wanna add a new client?", vbYesNo) = vbYes Then
'Unload Me            
frmNewClient.show
'frmPOS.show
            Else
            Me.cmbName = "Cash Client"
         End If
      End If
   End With
End Sub

Private Sub txtMobile_Change()
Call cmbName_Change
End Sub

Private Sub txtID_Change()
Call cmbName_Change
End Sub

Private Sub UserForm_Initialize()
Dim Cl As Range
   Set UfDic = CreateObject("scripting.dictionary")
   UfDic.CompareMode = 1
   For Each Cl In Sheet5.Range("Client_Details").Columns(2).Rows
      If Not UfDic.exists(Cl.Value) Then UfDic.Add Cl.Value, Array(Cl.Offset(, -1).Value, Cl.Offset(, 1).Value)
   Next Cl
   Me.cmbName.List = UfDic.keys
End Sub
 
I'm afraid that has me stumped.

The first time the form is opened, both typing into the combo box or selecting from the drop down trigger the _Change event,
but after opening the form a second time only selecting from the drop down triggers the _Change event, typing in the combo does not.

I've never seen this before and so far my googling hasn't turned up anything that would indicate what the cause is.
You may need to post this as a separate question so others will see it.
 
Upvote 0

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Forum statistics

Threads
1,213,557
Messages
6,114,288
Members
448,563
Latest member
MushtaqAli

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top