Need Help With Option Group Code

J

joann007

I'm sure this is very easy, but I have no idea how to go about it:

I've created a flexible search page. On this page, the user can
search for records using all of the criteria or only one criteria.
Everything works fine except for the criteria selection from an option
group. The name of this option group is OptionGroup (how creative is
that?), and the three radio buttons given the user three different
possibilities: Option 1-Choose records that are labled as "open".
Option 2- Choose records labled as "closed". Option 3- Choose
overdue records by selecting those records whose tickledates are
previous to today. Here's the code that I wrote up. I know something
is wrong with it since it's not working, so any information would be
greatly appreciated.

'Search by radio button selection, and gets exact match of field.
If no radio button is selected, than loops onto the next criteria

If Not IsNull(Me.OptionGroup) Then
Select Case Me.OptionGroup
Case 1
strWhere = strWhere & " ([Status] = Open) AND "
Case 2
strWhere = strWhere & " ([Status] = Closed) AND "
Case 3
strWhere = strWhere & " ([Status] = Open AND
([TickleDate] < Now())) "


End Select
End If
 
G

GH

I'm sure this is very easy, but I have no idea how to go about it:

...

'Search by radio button selection, and gets exact match of field.
If no radio button is selected, than loops onto the next criteria

If Not IsNull(Me.OptionGroup) Then
Select Case Me.OptionGroup
Case 1
strWhere = strWhere & " ([Status] = Open) AND "
Case 2
strWhere = strWhere & " ([Status] = Closed) AND "
Case 3
strWhere = strWhere & " ([Status] = Open AND
([TickleDate] < Now())) "

End Select
End If

Are the values in your table actually Open and Closed? If so, these
are string values that require quotes. In other words [Status] =
'Open'. If this does not fix the issue, are you getting any specific
error? Have you tried viewing your final strWhere or your final query
in the Immediate window to see how it looks once all choices have been
executed? Sometimes seeing your query here can help identify errors
in the build of the SQL string.

HTH
- GH
 
J

joann007

Thanks for the reply! You're were totally right about the strings.
Once I put quotation marks in front of open and closed, those two
worked perfectly. I was still having problems with option 3, but you
suggestion of looking at the code in the immediate window was great
advice. Somehow I had the paratheses all messed up and that's why I
was getting the error.

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top