Option Group Filtering

G

Guest

I have searched and read anything to do with option group filtering in this
thread but am not understanding what I am reading so here is the question.

I have an option group on my form that has 5 different check boxes.
All, Active, Billout, Hold, and Storage.

I want to filter my form frmOrderInfo based on what is checked. The field
that holds the value I want to filter on is my field [Order Status]

I could use help with syntax and what is the best way to apply the filter.
Would it be based on a case statement looking for the value of the frame or
on each check box in the option group?

Thanks in advance for any assistance you may be able to provide.
 
M

MikeC

This is air code, but I think it's pretty close. You can execute this in
the On Click event for the option group or for a command button. It uses a
Select Case on the value of the option group. Comments are below.

'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Private Sub optOrderStatus_Click()
On Error GoTo Err_optOrderStatus_Click

'For simplicity, I will assume that the below constant values have been
assigned
'to each check box in the option group *and* that these values coincide
with the
'"Order Status" values to be used for filtering records.

'Also assuming one of the check boxes has been set as a default in the
option
'group.

Const conAll As Integer = 1
Const conActive As Integer = 2
Const conBillout As Integer = 3
Const conHold As Integer = 4
Const conStorage As Integer = 5

Dim intOrderStatus As Integer

With Me
.FilterOn = True
'Assuming option group control is named "optOrderStatus".
Select Case !optOrderStatus

Case conAll

intOrderStatus = conAll

Case conActive

intOrderStatus = conActive

Case conBillout

intOrderStatus = conBillout

Case conHold

intOrderStatus = conHold

Case conStorage

intOrderStatus = conAll

Case Else

'Do something else, like display an error message.

End Select

End With

DoCmd.ApplyFilter , "[Order Status] = " & intOrderStatus

Exit_optOrderStatus_Click:
Exit Sub

Err_optOrderStatus_Click:
MsgBox Err.Description
Resume Exit_optOrderStatus_Click

End Sub

'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
G

Guest

Thank you for your reply. I must have misquoted in my previous. I set the
options in the option group to be 1-5 but the data that is in the [Order
Status] field is text
"All"
"Active"
"Billout"
"Hold"
"Storage"

Since this is looking for an interger, and I need it to look for the above
text in the [Order Status] field, when it gets to the Filter code I get a
The apply filter action was canceled.

Is there a quick fix to make this?

Basically if optOrdersStatus value = 2 then filter on field [Order Status]
where [Order Status] = "Active"

Thanks Again





MikeC said:
This is air code, but I think it's pretty close. You can execute this in
the On Click event for the option group or for a command button. It uses a
Select Case on the value of the option group. Comments are below.

'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Private Sub optOrderStatus_Click()
On Error GoTo Err_optOrderStatus_Click

'For simplicity, I will assume that the below constant values have been
assigned
'to each check box in the option group *and* that these values coincide
with the
'"Order Status" values to be used for filtering records.

'Also assuming one of the check boxes has been set as a default in the
option
'group.

Const conAll As Integer = 1
Const conActive As Integer = 2
Const conBillout As Integer = 3
Const conHold As Integer = 4
Const conStorage As Integer = 5

Dim intOrderStatus As Integer

With Me
.FilterOn = True
'Assuming option group control is named "optOrderStatus".
Select Case !optOrderStatus

Case conAll

intOrderStatus = conAll

Case conActive

intOrderStatus = conActive

Case conBillout

intOrderStatus = conBillout

Case conHold

intOrderStatus = conHold

Case conStorage

intOrderStatus = conAll

Case Else

'Do something else, like display an error message.

End Select

End With

DoCmd.ApplyFilter , "[Order Status] = " & intOrderStatus

Exit_optOrderStatus_Click:
Exit Sub

Err_optOrderStatus_Click:
MsgBox Err.Description
Resume Exit_optOrderStatus_Click

End Sub

'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

cvegas said:
I have searched and read anything to do with option group filtering in this
thread but am not understanding what I am reading so here is the question.

I have an option group on my form that has 5 different check boxes.
All, Active, Billout, Hold, and Storage.

I want to filter my form frmOrderInfo based on what is checked. The field
that holds the value I want to filter on is my field [Order Status]

I could use help with syntax and what is the best way to apply the filter.
Would it be based on a case statement looking for the value of the frame
or
on each check box in the option group?

Thanks in advance for any assistance you may be able to provide.
 
M

MikeC

Yes, the solution is easy,

1) Change "Dim intOrderStatus As Integer" to "Dim strOrderStatus As
String".

2) Replace each of the remaining 6 instances of "intOrderStatus" with
"strOrderStatus".

3) For each case statement, set "strOrderStatus" equal to the appropriate
text string. Example:

Case conAll

strOrderStatus = "All"




cvegas said:
Thank you for your reply. I must have misquoted in my previous. I set
the
options in the option group to be 1-5 but the data that is in the [Order
Status] field is text
"All"
"Active"
"Billout"
"Hold"
"Storage"

Since this is looking for an interger, and I need it to look for the above
text in the [Order Status] field, when it gets to the Filter code I get a
The apply filter action was canceled.

Is there a quick fix to make this?

Basically if optOrdersStatus value = 2 then filter on field [Order Status]
where [Order Status] = "Active"

Thanks Again





MikeC said:
This is air code, but I think it's pretty close. You can execute this in
the On Click event for the option group or for a command button. It uses
a
Select Case on the value of the option group. Comments are below.

'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Private Sub optOrderStatus_Click()
On Error GoTo Err_optOrderStatus_Click

'For simplicity, I will assume that the below constant values have
been
assigned
'to each check box in the option group *and* that these values
coincide
with the
'"Order Status" values to be used for filtering records.

'Also assuming one of the check boxes has been set as a default in
the
option
'group.

Const conAll As Integer = 1
Const conActive As Integer = 2
Const conBillout As Integer = 3
Const conHold As Integer = 4
Const conStorage As Integer = 5

Dim intOrderStatus As Integer

With Me
.FilterOn = True
'Assuming option group control is named "optOrderStatus".
Select Case !optOrderStatus

Case conAll

intOrderStatus = conAll

Case conActive

intOrderStatus = conActive

Case conBillout

intOrderStatus = conBillout

Case conHold

intOrderStatus = conHold

Case conStorage

intOrderStatus = conAll

Case Else

'Do something else, like display an error message.

End Select

End With

DoCmd.ApplyFilter , "[Order Status] = " & intOrderStatus

Exit_optOrderStatus_Click:
Exit Sub

Err_optOrderStatus_Click:
MsgBox Err.Description
Resume Exit_optOrderStatus_Click

End Sub

'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

cvegas said:
I have searched and read anything to do with option group filtering in
this
thread but am not understanding what I am reading so here is the
question.

I have an option group on my form that has 5 different check boxes.
All, Active, Billout, Hold, and Storage.

I want to filter my form frmOrderInfo based on what is checked. The
field
that holds the value I want to filter on is my field [Order Status]

I could use help with syntax and what is the best way to apply the
filter.
Would it be based on a case statement looking for the value of the
frame
or
on each check box in the option group?

Thanks in advance for any assistance you may be able to provide.
 

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