Like in a Dcount

bunji

Registered User.
Local time
Today, 07:45
Joined
Apr 26, 2005
Messages
124
Is it possible to put a like "*" me.Name "*" in a dcount

My Dcount is:

DCount("*", "[tblCustomers]", "[Surname]= '" & Me.Surname & "' And [First name] = '" & Me.First_Name & "' And [Company Name] = '" & Me.Company_Name & "'")

I tried adding this but not

If DCount("*", "[tblCustomers]", "[Surname]= '" & Like "*" & Me.Surname & "' & "*" And [First name] = '" & Me.First_Name & "' And [Company Name] = '" & Me.Company_Name & "'")

but it didnt like the 'Like' expression
 
bunji said:
If DCount("*", "[tblCustomers]", "[Surname]= '" & Like "*" & Me.Surname & "' & "*" And [First name] = '" & Me.First_Name & "' And [Company Name] = '" & Me.Company_Name & "'")

You can't use Like and = in the same comparison.

Code:
If DCount("*", "[tblCustomers]", "[Surname] Like ""*" & Me.Surname & "*"" AND [First name] = """ & Me.First_Name & """ AND [Company Name] = """ & Me.Company_Name & """")
 
OK i tried the following:

If DCount("*", "[tblCustomers]", "[Surname] Like ""*" & Me.Surname & "*"" AND [First name] LIKE """"*" & Me.First_Name & "*"""" AND [Company Name] LIKE """"*" & Me.Company_Name & "*""""") Then

But get en error stating that i calcelled the previous opreation.
 
bunji said:
If DCount("*", "[tblCustomers]", "[Surname] Like ""*" & Me.Surname & "*"" AND [First name] LIKE """"*" & Me.First_Name & "*"""" AND [Company Name] LIKE """"*" & Me.Company_Name & "*""""") Then

You are using too many ""

Code:
If DCount("*", "[tblCustomers]", "[Surname] Like ""*" & Me.Surname & "*"" AND [First name] Like ""*" & Me.First_Name & "*"" AND [Company Name] Like ""*" & Me.Company_Name & "*""") Then
 
Thats what i thought. For help in my understanding, i take it that the " is suppose to encapuslate each section of the function
 
For some reason its not using the wildcards when the function is run, but picks up exact spelling,

i.e. it will detect the record bunji but not bunji1 or 1bunji
 
bunji said:
i take it that the " is suppose to encapuslate each section of the function

No, the "" is to replace the ' as an ' can appear in a person's name and would signify the end of a string prematurely and cause an error i.e. 'O'Donnely' So, the "" replaces' as it becomes a single " within a string.
 
Ok Thanks, but do you know it is recognising the wildcards? whole code is:

If DCount("*", "[tblCustomers]", "[Surname] Like ""*" & Me.Surname & "*"" AND [First name] Like ""*" & Me.First_Name & "*"" AND [Company Name] Like ""*" & Me.Company_Name & "*""") Then
Beep
MsgBox "This name already exists in the database!" & vbCrLf & " Please check for duplicate entry.", vbExclamation, ""
DoCmd.OpenQuery "QryDuplicateEntry"
 
Apologies i meant why the wild cards are not working, as it will only pick up the exact txt and not like?
 

Users who are viewing this thread

Back
Top Bottom