dbTalk Databases Forums  

year search

comp.databases.ms-access comp.databases.ms-access


Discuss year search in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
brino
 
Posts: n/a

Default year search - 03-30-2009 , 08:37 PM






hi all !

i need a user to select a year from a list eg . 2007,2008,2009 when
searching in a form that will run a query .
however the date format in the table is eg. "31/3/09" .
how can i just search through the year part of the date using this
method ?
i think there is some simple code you have to type in the query but im
not sure what it would be.

thanks

Reply With Quote
  #2  
Old   
Larry Linson
 
Posts: n/a

Default Re: year search - 03-30-2009 , 09:03 PM






Assuming the date field is named SomeDate, include in your Query Builder
Grid, define a calculated field as YearToSelect: Year([SomeDate]) and
assuming the control where the user selects a date is "cboSelectDate" on
Form frmMyQuery, in the Criteria line underneath the calculated field
"YearToSelect" enter Forms!frmMyQuery!cboSelectDate. That ought to do what
you want.

I generally do not run Queries in applications, but show the data either in
Forms or Reports, and I use the "WhereCondition" argument of the
DoCmd.OpenReport or DoCmd.OpenForm statement in a similar way to select the
data.

Larry Linson
Microsoft Office Access MVP


"brino" <bdsolutions2002 (AT) yahoo (DOT) com.au> wrote

Quote:
hi all !

i need a user to select a year from a list eg . 2007,2008,2009 when
searching in a form that will run a query .
however the date format in the table is eg. "31/3/09" .
how can i just search through the year part of the date using this
method ?
i think there is some simple code you have to type in the query but im
not sure what it would be.

thanks



Reply With Quote
  #3  
Old   
brino
 
Posts: n/a

Default Re: year search - 03-30-2009 , 10:50 PM



On Mar 31, 1:03*pm, "Larry Linson" <boun... (AT) localhost (DOT) not> wrote:
Quote:
Assuming the date field is named SomeDate, include in your Query Builder
Grid, define a calculated field as YearToSelect: Year([SomeDate]) and
assuming the control where the user selects a date is "cboSelectDate" on
Form frmMyQuery, in the Criteria line underneath the calculated field
"YearToSelect" enter Forms!frmMyQuery!cboSelectDate. That ought to do what
you want.

I generally do not run Queries in applications, but show the data either in
Forms or Reports, and I use the "WhereCondition" argument of the
DoCmd.OpenReport or DoCmd.OpenForm statement in a similar way to select the
data.

*Larry Linson
*Microsoft Office Access MVP

"brino" <bdsolutions2... (AT) yahoo (DOT) com.au> wrote in message

news:436df10d-b221-47af-824a-7f0766c95987 (AT) x29g2000prf (DOT) googlegroups.com...

hi all !

i need a user to select a year from a list eg . 2007,2008,2009 when
searching in a form that will run a query .
however the date format in the table is eg. "31/3/09" .
how can i just search through the year part of the date using this
method ?
i think there is some simple code you have to type in the query but im
not sure what it would be.

thanks
thats brilliant !!

thanks for your help


Reply With Quote
  #4  
Old   
Larry Linson
 
Posts: n/a

Default Re: year search - 04-01-2009 , 02:17 AM



"brino" <bdsolutions2002 (AT) yahoo (DOT) com.au> wrote

Quote:
thats brilliant !!
Thanks for your kind words.

How many records in the table? If there are tens or hundreds of thousands,
you should use an approach as described by Rick Brandt. But, if performance
were a significant factor, I might go even farther, and use VBA code to
construct SQL with the _values_ from the Form Controls, rather than using a
reference to those controls. If you have no more than hundreds or thousands
of records, the performance difference is not likely to be significant --
but, in any case, Rick's approach will be faster than the one I gave you.

Quote:
thanks for your help
You are welcome.

Larry Linson
Microsoft Office Access MVP




__________ Information from ESET Smart Security, version of virus signature database 3979 (20090331) __________

The message was checked by ESET Smart Security.

http://www.eset.com






Reply With Quote
Reply




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 On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.