ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,832
- Office Version
- 2007
- Platform
- Windows
Morning,
I am using the code supplied below.
The code checks to make sure that the value entered in TextBox4 doesnt already exist on my worksheet before it then makes the save.
If there is a matching invoice number alreay then i see the msgbox show up advising me "Already Exists"
I would like this to only apply to numbers as sometimes i now need to enter N/A
Obviously only 1 instance of N/A will allow me to make the save.
So can we some how please make N/A exempt from this check & thus allow it to be saved.
I am using the code supplied below.
The code checks to make sure that the value entered in TextBox4 doesnt already exist on my worksheet before it then makes the save.
If there is a matching invoice number alreay then i see the msgbox show up advising me "Already Exists"
I would like this to only apply to numbers as sometimes i now need to enter N/A
Obviously only 1 instance of N/A will allow me to make the save.
So can we some how please make N/A exempt from this check & thus allow it to be saved.
Code:
Private Sub CommandButton1_Click()
With Sheets("DATABASE")
If Not Application.CountIf(.Columns(16), Me.TextBox4.Text) > 0 Then
Rows("6:6").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A6").Select
Range("A6:Q6").Borders.LineStyle = xlContinuous
Range("A6:Q6").Borders.Weight = xlThin
Range("A6:Q6").Interior.ColorIndex = 6
Range("M6") = Date
Range("$Q$6").Value = "'NO NOTES FOR THIS CUSTOMER"
Range("$Q$6").HorizontalAlignment = xlCenter
.Range("A6").Value = Me.TextBox1.Text
.Range("B6").Value = Me.ComboBox1.Text
.Range("C6").Value = Me.ComboBox2.Text
.Range("D6").Value = Me.ComboBox3.Text
.Range("E6").Value = Me.ComboBox4.Text
.Range("F6").Value = Me.ComboBox5.Text
.Range("G6").Value = Me.ComboBox6.Text
.Range("H6").Value = Me.ComboBox7.Text
.Range("I6").Value = Me.ComboBox8.Text
.Range("J6").Value = Me.ComboBox9.Text
.Range("K6").Value = Me.ComboBox10.Text
.Range("L6").Value = Me.ComboBox11.Text
.Range("M6").Value = Me.TextBox2.Text
.Range("N6").Value = Me.ComboBox12.Text
.Range("O6").Value = Me.TextBox3.Text
.Range("P6").Value = Me.TextBox4.Text
.Range("Q6").Value = Me.TextBox5.Text
Else
With Me.TextBox4
MsgBox "Invoice Number " & .Text & " Already Exists", vbCritical, "Duplicate Invoice Number"
.Value = "": .SetFocus
End With
Exit Sub
End If
End With
Dim ctrl As MSForms.Control
For Each ctrl In Me.Controls
Select Case True
Case TypeOf ctrl Is MSForms.TextBox
ctrl.Value = ""
Case TypeOf ctrl Is MSForms.combobox
ctrl.Value = ""
End Select
Next ctrl
MsgBox "Database Has Been Updated", vbInformation, "SUCCESSFUL MESSAGE"
TextBox2.Value = Now
TextBox2 = Format(TextBox2.Value, "dd/mm/yyyy")
TextBox1.SetFocus
TextBox5.Value = "NO NOTES FOR THIS CUSTOMER"
End Sub