INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

datepart d function oops

datepart d function oops

(OP)
Hi,

The code below should produce all the days of the year in the database the user ask for in a query

aliasmyday: (DatePart("d",[Saledate])

criteria Like ("*" & [Search_My_daynumber])

for example if the user input 01 it should brings all the data of all the years on the first day of each month present in
the databases

RE: datepart d function oops

DatePart returns number, why do you compare it with string instead directly have [Search_My_daynumber] in criteria? You may have problem with single digit days, for instance if DatePart returns 1, you get in criteria Like *01, resulting no match.

combo

RE: datepart d function oops

(OP)
try your code doesn't work

query must provide the following results
if user input 1
it should give the sales on the 1 of January first of 1 February and so on.

RE: datepart d function oops

Why do you think you need a like? Does not make sense. So assume the user enters "2" do you want to return 2, 20, 21..29.

Should simply be
Day([SaleDate]: returns 1 to 31
[search_My_DayNumber]: input should be 1,2 to 31 and not 01..09
If you input a 01 it will be interpretted as a string and should not compare as combo has stated.

RE: datepart d function oops

(OP)
If the user enter 2 it should bring up 2 of January the 2 of February and the 2 of march and so on

RE: datepart d function oops

I would add a combo box with 1-31 as a row source on a form and then set the criteria to:

CODE --> Criteria

=Forms![YourFormName]![YourComboBoxName] 

It is easiest to use the Day([SaleDate]) as pointed out by MajP.

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016

RE: datepart d function oops

Quote:

If the user enter 2 it should bring up 2 of January the 2 of February and the 2 of march and so on
Yes, everyone has figured that out and has told you how to do it correctly. Why do you keep saying that? Using "like" does not get you there. Do you understand what the "like" syntax does?

RE: datepart d function oops

(OP)
Thank you MajP for the code

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close