On the Edge of Insanity...... (1 Viewer)

themanof83

Registered User.
Local time
Today, 22:36
Joined
May 1, 2008
Messages
73
Please can someone spot the errors of my ways, this is driving me nuts...

I am trying to see if a record already exists matching the criteria used in the DCount function. I have used this successfully in other areas of my project but it doesn't seem to like this one!!!
I am getting a Data Type mismatch in Criteria expression - error.

Folder Name (text) and Programme ID (number) are fields in table Folders. I am seeing whether a record exists in the table that matches the values entered on a form (Me.Main_Folder and Me.ProgID). As follows:

stLinkCriteria = "[Folder Name]=" & "'" & Me.Main_Folder & "' AND [Programme ID]='" & Me.ProgID & "'"

Dup = DCount("[Folder Name]", "Folders", stLinkCriteria)

I guarentee its something stupid I've done but I have no hair left....

Thanks in advance....!
 

KenHigg

Registered User
Local time
Today, 18:36
Joined
Jun 9, 2004
Messages
13,327
Is [Programme ID] a numeric data type?
 

CyberLynx

Stuck On My Opinions
Local time
Today, 15:36
Joined
Jan 31, 2008
Messages
585
stLinkCriteria = "[Folder Name]='" & Me.Main_Folder & "' AND [Programme ID]=" & Me.ProgID

Dup = DCount("[Folder Name]", "Folders", stLinkCriteria)

.
 

themanof83

Registered User.
Local time
Today, 22:36
Joined
May 1, 2008
Messages
73
Thanks CyberLynx, now works fine...!

Could you possibly explain the logic behind the quotation marks etc. as it is a common problem I have?

Thanx again.
 

KenHigg

Registered User
Local time
Today, 18:36
Joined
Jun 9, 2004
Messages
13,327
Anything that is a text datatype needs quotes around it whereas numeric data types do not. So if Me.Main_Folder equals 'MyFolderName' then the [Folder Name] parts looks something like:

[Folder Name] = 'MyFolderName'

What you had there should have actually worked. It was the numeric [Programme ID] part that you put quotes around which caused the error and it didn't need the quotes. So that part needed to look something like:

[Programme ID] = 1234

In your code that errored that part evaluated to something like:

[Programme ID] = '1234'

Hope that makes sense - :)
 

CyberLynx

Stuck On My Opinions
Local time
Today, 15:36
Joined
Jan 31, 2008
Messages
585
And...if you are going to be applying a Date or Time to a query string (SQL) or Filter etc., it will need to be enclosed between the Hash Marks ( # ). For Example:

[Start Date] = #" & Me.MyDateTextBox & "#"

which evaluates to

[Start Date] = #01/01/2008#

.
 

Users who are viewing this thread

Top Bottom