473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

filtering subform using radio buttons

Hi.

Im trying to program my radio buttons to filter data for student pass/fail in a sub form called [front screen data] I have using help found here got this far but its not working and Im not sure why. my radio buttons are as follow
#1 pass
#2 fail
#3 both

my field is [PassFail]

This is what i have

Private Sub Frame29_BeforeUpdate(Cancel As Integer)
Select Case Me!Frame29
Case 1
Me.Filter = "Pass or Fail = Pass"
Me.FilterOn = True
MsgBox "Pass or Fail = Pass"
Case 2
Me.Filter = "Pass or Fail = Fail"
Me.FilterOn = True
MsgBox "Pass or Fail=Fail"
Case 3
Me.FilterOn = False
MsgBox "Show All Records"
End Select
End Sub

Any help would be appreciated

Thanks
Dec 30 '10 #1

✓ answered by Stewart Ross

Hi. Firstly, you'll need to use the AfterUpdate event of your frame, not its BeforeUpdate event. Secondly, if the field you are filtering on is called Pass or Fail you will need to enclose the field name in brackets, like this: [Pass or Fail]. Thirdly, the text values 'Pass' and 'Fail' must be enclosed in quotes:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Frame29_AfterUpdate()
  2.   Select Case Me!Frame29
  3.   Case 1
  4.     Me.Filter = "Pass or Fail = Pass"
  5.     Me.FilterOn = True
  6.   Case 2
  7.     Me.Filter = "Pass or Fail = Fail"
  8.     Me.FilterOn = True
  9.   Case 3
  10.     Me.FilterOn = False
  11.   End Select
  12. End Sub
  13.  
If the frame (and consequently its AfterUpdate event code) is on the main form you will need to refer to the subform specifically, whereas at present the code above may be referring to the main form. If you need to filter the subform from the main form, the syntax is

Expand|Select|Wrap|Line Numbers
  1. Me![YourSubformControlName].Form.Filter = "[Pass or Fail] = 'Pass'"
  2. Me![YourSubformControlName].Form.FilterOn = ***
(Of course you would need to substitute the actual name of your subform control for the placeholder in the example above.)

-Stewart

11 5740
Stewart Ross
2,545 Expert Mod 2GB
Hi. Firstly, you'll need to use the AfterUpdate event of your frame, not its BeforeUpdate event. Secondly, if the field you are filtering on is called Pass or Fail you will need to enclose the field name in brackets, like this: [Pass or Fail]. Thirdly, the text values 'Pass' and 'Fail' must be enclosed in quotes:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Frame29_AfterUpdate()
  2.   Select Case Me!Frame29
  3.   Case 1
  4.     Me.Filter = "Pass or Fail = Pass"
  5.     Me.FilterOn = True
  6.   Case 2
  7.     Me.Filter = "Pass or Fail = Fail"
  8.     Me.FilterOn = True
  9.   Case 3
  10.     Me.FilterOn = False
  11.   End Select
  12. End Sub
  13.  
If the frame (and consequently its AfterUpdate event code) is on the main form you will need to refer to the subform specifically, whereas at present the code above may be referring to the main form. If you need to filter the subform from the main form, the syntax is

Expand|Select|Wrap|Line Numbers
  1. Me![YourSubformControlName].Form.Filter = "[Pass or Fail] = 'Pass'"
  2. Me![YourSubformControlName].Form.FilterOn = ***
(Of course you would need to substitute the actual name of your subform control for the placeholder in the example above.)

-Stewart
Dec 30 '10 #2
Thanks sooooo much. This worked perfectly. I had tried to put the field name in brackets but when I did this i removed the speech marks causing an error. Didnt think about the quotation marks though.

Also thought about the subform bit but tried to add that to [frontend subform]![pass or fail] so didnt work. This worked perfectly. I am forever grateful

Jody
Dec 30 '10 #3
Ok so just noticed something...added the syntax just before the select case me part and now when I use the form it sort of works.

The screen when I press pass works fine and shows all that have passed but when I select fail the subform refreshes but remains the same (showing all passed) so when I select Both the same happens (showing all passed)

any ideas???
Dec 30 '10 #4
Stewart Ross
2,545 Expert Mod 2GB
Not sure; I'd suggest that you add the following statement just after the End Select statement to provide some state tracing of what is going on:

Expand|Select|Wrap|Line Numbers
  1. msgbox "Button value: " & Me!Frame29 & " - Filter: " & Me.Filter & " - Filter Status: " & IIF(Me.FilterOn, "On", "Off")
If, as I suspect is the case, the filter is being applied as expected then the problem is in the relationship between your main form and your subform in some way or another.

If the filter shown in the messagebox is not as expected you will need to check the context of the button value and the case statement involved.

-Stewart
Dec 30 '10 #5
As suspected when the filter is selected the pop up says the filter status is off. Do you have any suggestions??

I am unsure where to go as I am not a novice but I am also not an expert. I have some knowledge but apparently not enough.

Any advice you have is gratefully received.
Dec 30 '10 #6
Stewart Ross
2,545 Expert Mod 2GB
If you could post the whole of the current AfterUpdate code I'll check the syntax for you.

Please be aware that filtering the main form will in no way affect the subform's records.

-Stewart
Dec 30 '10 #7
This is what I have now completely. I added in some requery's to updat it each time to check if that was the problem so here is everything I got

Private Sub Frame29_AfterUpdate()
Me![front screen data subform].Form.Filter = "[Pass or Fail] = 'Pass'"
Me![front screen data subform].Form.FilterOn = True
Select Case Me!Frame29
Case 1
Me.Filter = "[Pass or Fail] = 'Pass'"
Me.FilterOn = True
MsgBox "You have requested to view students who have Passed only"
Forms![Front Screen]![front screen data subform].Requery
Case 2
Me.Filter = "[Pass or Fail] = 'Fail'"
Me.FilterOn = True
MsgBox "You have requested to view students who have Failed only"
Forms![Front Screen]![front screen data subform].Requery
Case 3
Me.Filter = ""
Me.FilterOn = False
MsgBox "You have requested to See All Records"
Forms![Front Screen]![front screen data subform].Requery
End Select
MsgBox "Button value: " & Me!Frame29 & " - Filter: " & Me.Filter & " - Filter Status: " & IIf(Me.FilterOn, "On", "Off")

End Sub

Thanks
Dec 30 '10 #8
Stewart Ross
2,545 Expert Mod 2GB
Problem is that in your Select Case statement you are applying filtering to the main form, not to the subform. The statements you added before the Select Case apply a filter to the subform - the case statement is having no effect as it is filtering the main form only.

I'd replace the AfterUpdate code as follows:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Frame29_AfterUpdate()
  2.   Select Case Me!Frame29
  3.   Case 1
  4.     Me![front screen data subform].Form.Filter = "[Pass or Fail] = 'Pass'"
  5.     Me![front screen data subform].Form.FilterOn = True
  6.     MsgBox "You have requested to view students who have Passed only"
  7.   Case 2
  8.     Me![front screen data subform].Form.Filter = "[Pass or Fail] = 'Fail'"
  9.     Me![front screen data subform].Form.FilterOn = True
  10.     MsgBox "You have requested to view students who have Failed only"
  11.   Case 3
  12.     Me![front screen data subform].Form.Filter = ""
  13.     Me![front screen data subform].Form.FilterOn = False
  14.     MsgBox "You have requested to See All Records"
  15.   End Select
  16.   MsgBox "Button value: " & Me!Frame29 & " - Filter: " & Me![front screen data subform].Form.Filter & " - Filter Status: " & IIf(Me![front screen data subform].Form.FilterOn, "On", "Off")
  17. End Sub
There is no need for the requery statements, as turning the filter on or off requeries the subform automatically.

-Stewart
Dec 30 '10 #9
Thank you soooo much. This has been bugging me for over 3 days before I sent you the message so I really welcome this.

Thanks
Dec 30 '10 #10
Hi again,

This has been working fine but Im trying to use a DCount to count the records in my subform based on my selections using a my drop downs but for some reason it doesnt work based on my selections using the radio buttons.

This is the code I have added (after the End Select)
[Text54] = DCount("[Surname]", "front screen data")

Any ideas why this isnt working??(it isnt updating in the DCount box)

Thanks
Jan 2 '11 #11
Stewart Ross
2,545 Expert Mod 2GB
Although you are posing a different question - which should be in its own thread - DCount is a very simple function which does what it is asked to do. A quick way to check what is going on is to replace your current line with this one:

Msgbox "Rows in front screen data: " & DCount("*", "front screen data")

This will show you the value of the number of rows in table or query front screen data. If this value is 0 then there are no rows in that data source.

I cannot tell you more about what to check given that I know nothing at all about what the datasource 'front screen data' is or how it is updated.

-Stewart
Jan 3 '11 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Newbie | last post by:
I currently have a set of simple calculations to determine square footage and multuply that by a dollar amount per foot. I use form fields that are filled in by the user, and then the Submit...
1
by: sman | last post by:
Hi, I recently read this article on About.com on how to create required fields for a form: http://javascript.about.com/library/scripts/blformvalidate.htm Everything works great except that there...
10
by: DettCom | last post by:
Hello, I would like to be able to display or hide fields based on whether a specific Yes/No radio button is selected. This is in conjunction with a posting a just made here in the same group...
0
by: Glenn | last post by:
I have a datagrid which i have added a extra template column to which was a radio button in it. The end user should use the radio button to select one of the items and then click a button to...
6
by: shror | last post by:
i want to add a midi file to my pages and i want to put two radio buttons so that on is on and the other is off so that the users can start or stop the file playing by choosing one of the radio...
1
by: worldapps | last post by:
Hi, Can any one help me in my fallowing tasks. 1) I have Table po_headers in that i have two columns like po_number, po_type In my form Layout I have to take
3
by: Eric | last post by:
Hi. I have this Combobox name 'Origin' that contains all states and countries. I would like to create two Radio buttons (State and Country) that when you select State, the combobox will query only...
8
by: eeffoc | last post by:
I've got a set of six radio buttons inside of a list box and what I'm trying to accomplish is generate a random number all with different ranges (Dice for d&d) depending on what radio button is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.