Hi, I'm having trouble with a line in my code, it compiles...
but whenever I run it I get a #91 error
The code is supposed to identify duplicates in a field.
Function ValidateEntries() As Boolean
ValidateEntries = True
Dim iPVNr As Variant
Dim sh As Worksheet
iPVNr = frmForm.txtPVnr.Value
With frmForm
'~~> Default colors for mandatory fields
.txtPVnr.BackColor = vbWhite
.txtDatum.BackColor = vbWhite
.cmbPost.BackColor = vbWhite
.cmbLocatie.BackColor = vbWhite
.cmbOvertreding.BackColor = vbWhite
.cmbBevinding.BackColor = vbWhite
.cmbOpslagplaats.BackColor = vbWhite
.cmbVerbalisant1.BackColor = vbWhite
.txtOpmerking.BackColor = vbWhite
'----------------------------------------------------------------------
If Trim(.txtPVnr.Value) = "" Then
MsgBox "Please enter PV nr.!", vbOKOnly + vbInformation, "PVnr"
ValidateEntries = False
.txtPVnr.BackColor = vbRed
.txtPVnr.SetFocus
Exit Function
End If
'~~> Validating Duplicate entries
If Not sh.Range("B:B").Find(what:=iPVNr, lookat:=xlWhole) Is Nothing Then
MsgBox "Duplicate PV nr. found!", vbOKOnly + vbInformation, "PVnr"
ValidateEntries = False
.txtPVnr.BackColor = vbRed
.txtPVnr.SetFocus
Exit Function
End If
Bookmarks