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
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