I have a button that users can add customers. When they click an inputbox records their result, and if the customer doesn't exist, it adds it to tblCustomer, if it does, it brings a warning message up. The problem is it always rejects the input whether it is a customer or not. The insert into command works fine, so it cannot be that.
Any ideas?
Code:
Private Sub cmdNewCustomer_Click()
Dim NewCustomer As String
Dim StrSQL As String
AddCustomer:
NewCustomer = InputBox("What is the new customers name?", "Add Customer")
If NewCustomer = "" Then
Exit Sub
ElseIf DCount("Customer", "tblCustomer", "' & NewCustomer & '") > 0 Then
MsgBox "That customer already exists!", vbInformation, "Duplicates Detected"
GoTo AddCustomer
End If
DoCmd.OpenTable "tblCustomer", acViewNormal, acAdd
DoCmd.GoToRecord acDataTable, "tblCustomer", acNewRec
StrSQL = "INSERT INTO tblCustomer (Customer) VALUES ('" & NewCustomer & "')"
CurrentDb.Execute StrSQL, dbfailonerror
DoCmd.Close acTable, "tblCustomer", acSaveYes
cboCustomer.Requery
MsgBox "New customer recorded!", vbInformation, "Entry Successful"
End Sub