Selected Answer
Divinedar
In the attached revised file, I changed a few things- firstly (in bold):
Private Sub UserForm_Initialize()
Call Reset
'### corrected this line
cboCustNo.RowSource = "=Customer_Info!A2:A50"
End Sub
(REVISION- the above corrects my earlier version) then for your cited code,
Private Sub cboCustNo_Change()
Dim myRange As Range, f As Range
Set myRange = Worksheets("Customer_Info").Range("A2:K50")
Set f = myRange.Find(What:=cboCustNo.Value, LookIn:=xlValues, Lookat:=xlWhole, MatchCase:=False) '<--| try and find combobox selected value
If f Is Nothing Then
cboCustNo.Value = "TBC (new Customer)" '### changed this
Else '<--| ... otherwise...
cboCustNo.Value = f.Offset(, 0)
txtCoName.Value = f.Offset(, 1)
txtContNm.Value = f.Offset(, 2)
txtAdrs1.Value = f.Offset(, 3)
txtAdrs2.Value = f.Offset(, 4)
txtSteNo.Value = f.Offset(, 5)
txtCity.Value = f.Offset(, 6)
txtState.Value = f.Offset(, 7)
txtZipCode.Value = f.Offset(, 8)
txtPhoneNo.Value = f.Offset(, 9)
txtFaxNo.Value = f.Offset(, 10)
End If
End Sub
so if you're don't pick an existing number (e.g. Q23002) from the pull-down but press a space say, that new message appears in the but haven't done that.
If you then fill in the other data fields and click the Submit button, this revised code will run:
Sub Submit()
Dim sh As Worksheet
Dim iRow As Long
Dim myRange As Range, f As Range ' ### added these
Set sh = ThisWorkbook.Sheets("Customer_Info")
iRow = [Counta(Customer_Info!A:A)] + 1 ' moved this
'If frmForm.cboCustNo.Value <> "" Then ' changed this
' ### added this
Set myRange = Worksheets("Customer_Info").Range("A2:A50")
' changed this to add form number
Set f = myRange.Find(What:=frmForm.cboCustNo.Value, LookIn:=xlValues, Lookat:=xlWhole, MatchCase:=False) '<--| try and find combobox selected value
If Not f Is Nothing Then
iRow = f.Row
End If
With sh
' replaced this
'.Cells(iRow, 1) = "=Row()-1" 'Dynamic Serial Number
.Cells(iRow, 1) = "Q23" & Format(iRow - 1, "000") 'New Dynamic Serial Number
.Cells(iRow, 2) = frmForm.txtCoName.Value
.Cells(iRow, 3) = frmForm.txtContNm.Value
.Cells(iRow, 4) = frmForm.txtAdrs1.Value
.Cells(iRow, 5) = frmForm.txtAdrs2.Value
.Cells(iRow, 6) = frmForm.txtSteNo.Value
.Cells(iRow, 7) = frmForm.txtCity.Value
.Cells(iRow, 8) = frmForm.txtState.Value
.Cells(iRow, 9) = frmForm.txtZipCode.Value
.Cells(iRow, 10) = frmForm.txtPhoneNo.Value
.Cells(iRow, 11) = frmForm.txtFaxNo.Value
'.Cells(iRow, 12) = [Text(Now(), "DD-MM-YYYY HH:MM:SS")]
End With
End Sub
In particular, the line:
.Cells(iRow, 1) = "Q23" & Format(iRow - 1, "000") 'New Dynamic Serial Number
will made a hard-coded consecutive value like Q23005 in column A of worksheet Customer_Info (and you'll see I added bogus details for that there via the UserForm). plus the UserForm details will display then new line.
(Note: If I made any other changes not listed above, I commented them in the code)
Hope this helps..