samedi 16 mars 2019

How to use If/Variable coding to catch duplicate entries in my Excel Userform (specificly)

NEWBIE here!!

Here's the code I wrote to prevent duplicate entries in both FULLNAME AND QBFileName. (I thought I had it working, but now this same code is preventing me from adding anyone... It tells me the client already exists. Which is only suppose to happen if there is another client by that FULLNAME or QBFileName.)
When I click the EDIT BUTTON, everything works wonderfully, but when I click ADD for NEW, it gives me a false validation.

* * * CODE BELOW * * *

Private Sub CmdButton_CONTINUE1_Click() 'When "CONTINUE" Button on TOP of UF is clicked.

Dim TargetRow As Integer '1st part of Variable for POSITION CONTROL Dim FullName As String 'Variable for FULL NAME to be used in msgbox when client is entered Dim QBFileName As String 'Variable Quick Books File Name

TargetRow = Sheets("Engine").Range("B3").Value + 1 'makes variable equal to COUNTA Formula on Engine worksheet +1 FullName = Txt_Client_First_Name & " " & Txt_Client_LAST_Name 'Variable configured: to be used in Msg when client is entered, it will show the full name

'''''''BEGINS VALIDATION CHECK: IF in 'add NEW' mode to prevent duplicate FULL NAME J Column entries**'''* If Application.WorksheetFunction.CountIf(Sheets("2019_ClientDatabase").Range("J3:J4000"), FullName) > 0 Then

MsgBox "Client already exists", 0, "Check" 'notify user of existing client Exit Sub 'exit the program routine End If 'ends validation check

''''BEGINS VALIDATION CHECK: IF in 'add NEW' mode to prevent duplicate QBFileName B Column entries''' If Application.WorksheetFunction.CountIf(Sheets("2019_ClientDatabase").Range("B3:B4000"), QBFileName) > 0 Then

MsgBox "Client already exists", 0, "Check" 'notify user of existing client Exit Sub 'exit the program routine End If 'ends validation check

*'''****BEGIN INPUT DATA INTO DATABASE****'''* Sheets("2019_ClientDatabase").Range("Data_Start").Offset(TargetRow, 0).Value = Txt_QB_File_Name 'QuickBooks File Name

'''ect....

Aucun commentaire:

Enregistrer un commentaire