Using variable for criteria in dcount()?

xPaul

Registered User.
Local time
Today, 13:10
Joined
Jan 27, 2013
Messages
65
Morning all,

I have a form with a number of combo boxes on it. These combo boxes provision a filter mechanism that I am creating.

Due to the combo boxes either one, two, three, (so on and so fourth) can be used to filter the record set.

Firstly I pick up the control source and name of the control and store it in a multidimensional array, once the filter button is pressed I then disable other controls on the form, and clear the control source of the combo box. I then loop through the controls and detect any that have changed and store the control source and value in another multidimensional array.

From this new array I loop through any controls that have changed and pick up the control source and and value to provision the normal criteria for a dcount - "[FieldName]='Value'", this loops through if there are more than two variables in the array and adds an AND between the statements. These are then stored in a variable.

The issue however comes in when I try to add it to the dcount, I get a result back for the count of all records in the unfiltered recordset and not what I am counting in the filter - for talks sake my complete count of records is 100, instead of returning 80 it is returning 100.

My dcount looks like this - DCount("[Field]", "
", strDcountQuery) which translates to DCount("[Field]", "
", "[Field2] = 'Value'").

Can I use a variable for the complete criteria in a dcount?

All values are in text format.

Best regards
 
yes, you can.
 
Indeed it does! Not sure what I changed, but after about 30 minutes of trying different things, it now works.

Thanks!
 

Users who are viewing this thread

Back
Top Bottom