Hi!
I have an unbound "search form" with controls, some of which are: Combo boxes (text data) for gender, profession and language, text boxes (numeric data) for upper and lower age limit. The user selects some, all or none of the criteria and then the opening other form should show records based on a query generated by the choices.
The DoCmd.OpenForm Where criteria with reference to combo box gives the wanted result as long as the combo box field is not empty. Problems start when it is empty.
I'm thinking of maybe having a block of Cases with all the permutations but that gives me (if I only had those 3 combo boxes) 7 different where criteria.
I figured the short way could possibly be assigning string variables a value according to each combo box and then concatenating the where criteria. That way I should end up with only one criteria which is built of the values of those combo boxes. This is where the single and double quotes haunt me to grave. I just do not get it right.
I might be totally lost here. So if I am, please show me to the right path or give another angle.
I have tried a bunch of things but this is what I'm trying to build now:
My idea is to have a similar if block for every combo box and to concatenate the values with something like this (I know this is not even close to correct syntax):
strWhere = strWhereGender & strWhereProfession & strWhereLanguage &
Whatever version I've tried, I haven't got it right (except for only strWhereAge. I guess it is because of numeric values). So what to try next?
I have an unbound "search form" with controls, some of which are: Combo boxes (text data) for gender, profession and language, text boxes (numeric data) for upper and lower age limit. The user selects some, all or none of the criteria and then the opening other form should show records based on a query generated by the choices.
The DoCmd.OpenForm Where criteria with reference to combo box gives the wanted result as long as the combo box field is not empty. Problems start when it is empty.
I'm thinking of maybe having a block of Cases with all the permutations but that gives me (if I only had those 3 combo boxes) 7 different where criteria.
I figured the short way could possibly be assigning string variables a value according to each combo box and then concatenating the where criteria. That way I should end up with only one criteria which is built of the values of those combo boxes. This is where the single and double quotes haunt me to grave. I just do not get it right.
I might be totally lost here. So if I am, please show me to the right path or give another angle.
I have tried a bunch of things but this is what I'm trying to build now:
Code:
If Me.cboProfession = "" Then
strWhereProfession = "LIKE '*'"
Else: strWhereProfession = "Profession = me.cboProfession"
End If
My idea is to have a similar if block for every combo box and to concatenate the values with something like this (I know this is not even close to correct syntax):
strWhere = strWhereGender & strWhereProfession & strWhereLanguage &
Code:
DoCmd.OpenForm "tempFrm", acNormal, , strWhere, acFormReadOnly, acWindowNormal
Whatever version I've tried, I haven't got it right (except for only strWhereAge. I guess it is because of numeric values). So what to try next?