Hi there,
i am having a problem with my userform. I am working on a master inventory list and hit a roadblock. I am filling in ten textboxes on a user form and when the add button is clicked the inventory group verifies that something is selected. that works fine. then it compares the id field with column 2 to check for matching values. if matching values are found a mcgbox appears and tells the user to ammend instead of adding, if no mathching value is found it then does the same for the serial # entered and cloumn 3 with the same results, if no match found it adds the data to the form.
The problem i am having is this if the id field or serial # field is left blank it says there is a matching value found. is there a way i can get it to not match a blank userform text box and a blank cell and also if someone enters lets say a 1 in the userform id field it will say there is a match it finds every cell with a 1 in it even if it is part of a longer string. Why is this? how can i get it to match exactly what is entered into the textbox
thank you for all your help
Private Sub cmbAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Dim rc1 As Range
Dim strfind, FirstAddress As String 'what to find
Dim strfind2, firstdaddress1 As String
Dim rsearch As Range 'range to search
Dim rsearch2 As Range
Dim f As Integer
Set ws = Worksheets("Data")
strfind = Me.TextBoxid.Value
strfind2 = Me.TextBoxserial.Value
'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
'check for a Group
If Trim(UserForm1.ComboBoxgroup.Value) = "" Then
UserForm1.ComboBoxgroup.SetFocus
MsgBox "Please select an Inventory Group"
Exit Sub
End If
Application.ScreenUpdating = False 'speed up
Set rsearch = Sheet2.Range("b2", Range("b65536").End(xlUp))
Set rsearch2 = Sheet2.Range("c2", Range("c65536").End(xlUp))
With rsearch
Set d = .Find(strfind, LookIn:=xlValues)
If Not d Is Nothing Then 'found it
MsgBox "A Matching NYPD ID # was found! Please click the Find button to ammend record.", vbExclamation, "Administrator Notification"
GoTo Do_something
End If
End With
With rsearch2
Set e = .Find(strfind2, LookIn:=xlValues)
If Not e Is Nothing Then
MsgBox "A Matching Serial # was found! Please click the Find button to ammend record.", vbExclamation, "Administrator Notifiaction"
GoTo Do_something
End If
End With
Set c = Range("a65536").End(xlUp).Offset(1, 0) 'write data
c.Value = Me.TextBoxtype.Value
c.Offset(0, 1).Value = Me.TextBoxid.Value
c.Offset(0, 2).Value = Me.TextBoxserial.Value
c.Offset(0, 3).Value = Me.TextBoxmanufacturer.Value
c.Offset(0, 4).Value = Me.TextBoxmodel.Value
c.Offset(0, 5).Value = Me.TextBoxdescription.Value
c.Offset(0, 6).Value = Me.TextBoxlocation.Value
c.Offset(0, 7).Value = Me.TextBoxnotes.Value
c.Offset(0, 8).Value = Me.ComboBoxgroup.Value
c.Offset(0, 9).Value = Me.TextBoxdate.Value
'restore form
With Me
.TextBoxtype.Value = vbNullString
.TextBoxid.Value = vbNullString
.TextBoxserial.Value = vbNullString
.TextBoxmanufacturer.Value = vbNullString
.TextBoxmodel.Value = vbNullString
.TextBoxdescription.Value = vbNullString
.TextBoxlocation.Value = vbNullString
.TextBoxnotes.Value = vbNullString
.ComboBoxgroup.Value = vbNullString
.TextBoxdate.Value = vbNullString
.cmbAmend.Enabled = False 'dont allow amendment or
.cmbDelete.Enabled = False 'dont allow record deletion
.cmbAdd.Enabled = True 'allow duplication
End With
Do_something:
Application.ScreenUpdating = True
End Sub
Bookmarks