A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Using Option group with a query



 
 
Thread Tools Display Modes
  #1  
Old January 29th, 2009, 09:35 AM posted to microsoft.public.access.gettingstarted
Phil
external usenet poster
 
Posts: 606
Default Using Option group with a query

Apologies if you have already seen this question I posted it yesterday but
could not find it this morning.

I have a form in a A2000 database that shows course details at the moment I
have it set to only show future courses by using Date() in the startdate. I
would like to have an option group to be able to switch between all courses
and future courses.

I have never used an option group befo

I created an option group called [Courses] with two options 1. Future
Courses 2. Alll Courses.

In the After update event for courses I have put:

Select Case Me!Courses
Case 1
Me!Courses = "Date()"

Case 2
Me!Courses = ""

End Select

I have also put this in the on load event for the form. and in the query
the form is based on under startdate I have added

=Forms!Events!Courses

This does nothing at all the form loads with no data and has does not change
if you change the option group

I hope someone can help

Thanks

Phil
  #2  
Old January 29th, 2009, 12:58 PM posted to microsoft.public.access.gettingstarted
John Spencer (MVP)
external usenet poster
 
Posts: 217
Default Using Option group with a query

You can't set the value of an Option group to "" or "Date()" set an option
group stores number values (notice that your code is testing if the option
group is equal to 1 or 2).

What you could do is set a filter on the form if your query returns all
records or you could change the query.

Private Sub Courses_AfterUpdate()

Select Case Me!Courses
Case 1
Me.Filter = "[DateField]Date()"
Me.FilterOn = True

Case 2
Me.Filter = "[DateField]Date()"
Me.FilterOn = True
End Sub

An alternative would be to set the query up with this criteria (assuming that
your date field always has a value

Field: [DateField]
Criteria: IIF(Forms!Events!Courses=1,Date(),#1900-01-01#)

If the date field is sometimes blank (null) then enter the criteria as
Field: [DateField]
Criteria: Date() or Forms!Events!Courses=2
Access will restructure the above when you save the query, but the query
should still work.

Your after update code would then become simpler
Private Sub Courses_AfterUpdate()
Me.Requery
End Sub


John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

Phil wrote:
Apologies if you have already seen this question I posted it yesterday but
could not find it this morning.

I have a form in a A2000 database that shows course details at the moment I
have it set to only show future courses by using Date() in the startdate. I
would like to have an option group to be able to switch between all courses
and future courses.

I have never used an option group befo

I created an option group called [Courses] with two options 1. Future
Courses 2. Alll Courses.

In the After update event for courses I have put:

Select Case Me!Courses
Case 1
Me!Courses = "Date()"

Case 2
Me!Courses = ""

End Select

I have also put this in the on load event for the form. and in the query
the form is based on under startdate I have added

=Forms!Events!Courses

This does nothing at all the form loads with no data and has does not change
if you change the option group

I hope someone can help

Thanks

Phil

  #3  
Old January 29th, 2009, 01:30 PM posted to microsoft.public.access.gettingstarted
Phil
external usenet poster
 
Posts: 606
Default Using Option group with a query

Thanks John

I took the filter route and it works great

Thanks again for the answer and the explanation

Phil

"John Spencer (MVP)" wrote:

You can't set the value of an Option group to "" or "Date()" set an option
group stores number values (notice that your code is testing if the option
group is equal to 1 or 2).

What you could do is set a filter on the form if your query returns all
records or you could change the query.

Private Sub Courses_AfterUpdate()

Select Case Me!Courses
Case 1
Me.Filter = "[DateField]Date()"
Me.FilterOn = True

Case 2
Me.Filter = "[DateField]Date()"
Me.FilterOn = True
End Sub

An alternative would be to set the query up with this criteria (assuming that
your date field always has a value

Field: [DateField]
Criteria: IIF(Forms!Events!Courses=1,Date(),#1900-01-01#)

If the date field is sometimes blank (null) then enter the criteria as
Field: [DateField]
Criteria: Date() or Forms!Events!Courses=2
Access will restructure the above when you save the query, but the query
should still work.

Your after update code would then become simpler
Private Sub Courses_AfterUpdate()
Me.Requery
End Sub


John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

Phil wrote:
Apologies if you have already seen this question I posted it yesterday but
could not find it this morning.

I have a form in a A2000 database that shows course details at the moment I
have it set to only show future courses by using Date() in the startdate. I
would like to have an option group to be able to switch between all courses
and future courses.

I have never used an option group befo

I created an option group called [Courses] with two options 1. Future
Courses 2. Alll Courses.

In the After update event for courses I have put:

Select Case Me!Courses
Case 1
Me!Courses = "Date()"

Case 2
Me!Courses = ""

End Select

I have also put this in the on load event for the form. and in the query
the form is based on under startdate I have added

=Forms!Events!Courses

This does nothing at all the form loads with no data and has does not change
if you change the option group

I hope someone can help

Thanks

Phil


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 04:00 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.