I've posted code that I was trying at that point of time by accident. Here I am posting another version of the code and Image of the Customer DB where Data posted via UserForm is stored.
Private Sub UserForm_Activate()
Dim LastRow As Range, strNextID As String
Set LastRow = Range("Customers!A65536").End(xlUp)
strNextID = "AA-" & Format(Right(WorksheetFunction.Max(Range("Customers!A8:A65536")), 5) + 1, "00000")
TextBox1.Value = strNextID
Dim v, e
With Sheets("Settings").Range("_paymentTerms")
v = .Value
End With
With CreateObject("scripting.dictionary")
.comparemode = 1
For Each e In v
If Not .exists(e) Then .Add e, Nothing
Next
If .Count Then Me.ComboBox1.List = Application.Transpose(.keys)
End With
End Sub
Private Sub Addreccord_Click()
Dim LastRow As Range, strNextID As String
Set LastRow = Range("Customers!A65536").End(xlUp)
strNextID = "AA-" & Format(Right(WorksheetFunction.Max(Range("Customers!A8:A65536")), 5) + 1, "00000")
LastRow.Offset(1, 0).Value = strNextID
LastRow.Offset(1, 1).Value = TextBox2.Text
LastRow.Offset(1, 2).Value = TextBox3.Text
LastRow.Offset(1, 3).Value = TextBox4.Text
LastRow.Offset(1, 4).Value = TextBox5.Text
LastRow.Offset(1, 5).Value = TextBox6.Text
LastRow.Offset(1, 6).Value = TextBox7.Text
LastRow.Offset(1, 7).Value = TextBox8.Text
LastRow.Offset(1, 8).Value = TextBox9.Text
LastRow.Offset(1, 9).Value = TextBox10.Text
LastRow.Offset(1, 10).Value = TextBox11.Text
LastRow.Offset(1, 11).Value = ComboBox1.Value
MsgBox "One record added to Customers List"
response = MsgBox("Do you want to enter another record?", _
vbYesNo)
If response = vbYes Then
TextBox1.Value = strNextID
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
TextBox9.Text = ""
TextBox10.Text = ""
TextBox11.Text = ""
TextBox2.SetFocus
Else
Unload Me
End If
End Sub
Private Sub Exitform_Click()
Unload Me
End Sub
Sub ClearFields_Click()
For Each ctrl In Me.Controls
Select Case TypeName(ctrl)
Case "TextBox"
ctrl.Text = ""
Case "ComboBox", "ListBox"
ctrl.ListIndex = -1
End Select
Next ctrl
End Sub
Bookmarks