On a user form i'm trying to verify that the entered part number in the text box "txtPartNo" doesn't already exist in a seperate workbook (Column F holds the part number). If the entered part number does exist then i display a message via msg box that a record does exist and it then references the specific planning number via the dpti variable (the planning number is in column A) in the same message box, we would then exit the sub and user form.
If no record of the part number exists in the seperate workbook then we can continue entering the remainder of the user form info.
When i enter a part number in the text box upon enter i immediately receive a "run time error 13", Type mismatch, not sure what i'm doing wrong, anyone have a suggestion?
At the end of the day I'm just trying to ensure that we don't have duplicate part numbers in the workbook.
Private Sub txtPartNo_AfterUpdate()
Dim Src As Workbook
Dim Dest As Workbook
Dim iRow As Long
Dim ws As Worksheet
Dim rng As Range
Dim rng1 As Range
Set Src = ThisWorkbook 'Source Workbook
Set Dest = Workbooks.Open("Test Log.xlsm")
Set ws = Dest.Worksheets("Test")
Set rng1 = ws.Columns(6).Find( _
what:=txtPartNo.Value, _
after:=ws.Cells(Rows.Count, 1), _
LookIn:=xlValues, _
Lookat:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not rng1 Is Nothing Then
dpti = ActiveCell.Offset(0, -6).Value
MsgBox "Material Number already Exists, check & dpti . ", vbExclamation, "Material Number Already Exists"
Exit Sub
Else
MsgBox "Material number is valid", vbExclamation, "Material Number Valid"
End If
Workbooks("DTPI Log.xlsm").Close SaveChanges:=False
End Sub
Bookmarks