473,387 Members | 1,899 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,387 software developers and data experts.

Criteria "Last working day"

Please can you help me. I am trying to find an expression that I can apply to a query in Access to return all records created yesterday. The complication is that our working week is Monday to Friday, therefore on Monday yesterday is actually Friday.

Thank you in anticipation.
Rgds
Bill Sullivan
Sep 19 '07 #1
5 8335
Scott Price
1,384 Expert 1GB
Please can you help me. I am trying to find an expression that I can apply to a query in Access to return all records created yesterday. The complication is that our working week is Monday to Friday, therefore on Monday yesterday is actually Friday.

Thank you in anticipation.
Rgds
Bill Sullivan
What is the data type for the date field you will be using to compare for 'yesterday'?

I'm assuming Date/Time, but is it mm/dd/yyyy?

How familiar are you with vba? What I think you'll end up needing is a special function that uses the Weekday() function to return the day # of the week. This isn't difficult to write, and if you need help with it, I'll be glad to take a closer look.

Regards,
Scott
Sep 20 '07 #2
Hi Scott

Thank you for your reply.

Firstly I am very new with VBA and in fact this is my first attempt at anything constructive.

The Data Type is indeed Date/Time but the format is dd/mm/yyyy. The field I am using is "Date Created", there is a separate field for "Time Created" but for the purposes of this project the time is irrelevant.

I would be extremely grateful for any help you can give me, I am running out of permutations to try and perhaps you might also be able to point me in the right direction for some basic principles.

Many thanks
Bill
Sep 20 '07 #3
Scott Price
1,384 Expert 1GB
Hi Scott

Thank you for your reply.

Firstly I am very new with VBA and in fact this is my first attempt at anything constructive.

The Data Type is indeed Date/Time but the format is dd/mm/yyyy. The field I am using is "Date Created", there is a separate field for "Time Created" but for the purposes of this project the time is irrelevant.

I would be extremely grateful for any help you can give me, I am running out of permutations to try and perhaps you might also be able to point me in the right direction for some basic principles.

Many thanks
Bill
In your query design view grid, go to the criteria for the [Date Created] field. Put this into the box: Yesterday(Date())

Then save the query and close it. Next press Alt+F11 to bring up the VBA editor window. Click the Insert menu, and choose Module. In the new module window that comes up, paste this code in:
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Public Function Yesterday(MyDay As Date) As String
  4.  
  5. Dim MyDate As Date
  6.  
  7. If WeekDay(MyDay) = 2 Then          'If MyDay is Monday
  8.     MyDate = MyDay - 3              'Subtract 3 days
  9. ElseIf WeekDay(MyDay) = 1 Then      'If MyDay is Sunday
  10.     MyDate = MyDay - 2              'Subtract 2 days
  11. Else
  12.     MyDate = MyDay - 1              'If any other day subtract 1 day
  13. End If
  14.  
  15. Yesterday = Format(MyDate, "dd/mm/yyyy")
  16.  
  17. End Function
You should delete the line numbers as they just confuse the issue. Click the Debug menu, click Compile. Save changes, go back to the database window and run your query.

If you have any problems, let me know!

Regards,
Scott
Sep 20 '07 #4
Hi Scott

Absolutely perfect thank you, and a million miles away from what I was trying, I would never have got there by myself.

Many thanks and best regards
Bill
Sep 20 '07 #5
Scott Price
1,384 Expert 1GB
Hi Scott

Absolutely perfect thank you, and a million miles away from what I was trying, I would never have got there by myself.

Many thanks and best regards
Bill
We like satisfied customers :-) Glad it's working for you!

Regards,
Scott
Sep 20 '07 #6

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

Similar topics

9
by: Marcus Sheen [UK] | last post by:
Have done searches for similar questions, but cannot find anything. Nor can I find any resources via Google (Javascript Source etc). Thinking about implementing a topical "On This Day" feature on...
2
by: Roy Veevers | last post by:
Hi, Need to run a script "last updated on" on a personal Website. Problem is the ones I can find rely on my servers synchronised time! This is one hour behind the correct time (Summertime) at my...
3
by: | last post by:
Hello, I am hoping someone else has thought about a date time calculation i need to perform. I would like to be able to calculate the number of "working minutes" between 2 dates, given my...
9
by: Robin Tucker | last post by:
Hiya, I need to test "relative dates" in my program, such as "last six months" or "last 3 months" or "in the last week" etc. How can I do this with a DateTime structure? ie. If NodeDate...
2
by: wsnyder3 | last post by:
I have many forms but all the information is related to one another. I wanted to know if there was a way that if someone updates a account that it will show the last date modified on all the...
11
by: Bruce Lawrence | last post by:
Ok, I'm baffled... I'm making a query in access 97 between 2 tables. There is a field in both tables called "DWGNO". OPENORD has a record with a DWGNO of "00000012345" DIEDATA has a record...
9
by: kocampo | last post by:
I just started working with Microsoft Access so I dont know much and Im trying to create a field that updates itself after changes have been made to the data in a table. I would like one that says...
4
by: JPG4 | last post by:
I have tried just about everything that I can think of, so now I turn to you all for help! I have created a form (titled "OAG") with an unbound textbox titled "DOW". I also have a Query that I...
22
by: MLH | last post by:
100 Dim db As Database, rst As Recordset 120 Set db = CurrentDb 140 PString = "SELECT qryBatchList.ReadyFor906, qryBatchList.BatchID FROM qryBatchList WHERE...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.