473,387 Members | 1,535 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.

Find records that contain dates of next Tuesday and onward

Hi,

I have a date field called StartDate, i am running a query in VBA to find any records with a StartDate of next Tuesday and onward. This the code i have, and its not working. Any ideas?

Private Sub cmdFuture_Click()

Dim sSQL As String

sSQL = "SELECT * FROM QueryCases WHERE Year(QueryCases.StartDate)* 53 + DatePart("ww", QueryCases.StartDate) = Year(Date())* 53 + DatePart("ww", Date()) + 3 ORDER BY QueryCases.StartDate;"

Me![ViewCasesSubform].Form.RecordSource = sSQL

End Sub

Thanks
Jan 17 '08 #1
4 2362
jaxjagfan
254 Expert 100+
Hi,

I have a date field called StartDate, i am running a query in VBA to find any records with a StartDate of next Tuesday and onward. This the code i have, and its not working. Any ideas?

Private Sub cmdFuture_Click()

Dim sSQL As String

sSQL = "SELECT * FROM QueryCases WHERE Year(QueryCases.StartDate)* 53 + DatePart("ww", QueryCases.StartDate) = Year(Date())* 53 + DatePart("ww", Date()) + 3 ORDER BY QueryCases.StartDate;"

Me![ViewCasesSubform].Form.RecordSource = sSQL

End Sub

Thanks
May need some adjustments depending on your definition of next Tuesday. In all of your records if startdate is 11/15/2007 for one record and 1/3/2008 for another record then next Tuesday would be different for each record.

If you have a control on your form for entering or selecting a date (or simply the next Tuesday from today (Now()). Then my WHERE clause remains the same you will have to redefine StartDate (Set i = Weekday(Me.txtDate)). "txtdate" could have a default value of Date() - today's date.

Private Sub cmdFuture_Click()

Dim sSQL As String
Dim i as int
Dim nxtDate as Date

Set i = WeekDay(StartDate)
Select Case i
Case 1
nxtDate = StartDate + 2 ' Today is Sunday - Tuesday is in 2 days or adjust code for next Tuesday add 9
Case 2
nxtDate = StartDate + 1 ' Today is Monday - Tuesday is tomorrow or adjust code for next Tuesday add 8
Case 3
nxtDate = StartDate + 7 ' Today is Tuesday - go to next Tuesday
Case 4
nxtDate = StartDate + 6 ' Today is Wednesday - go to next Tuesday
Case 5
nxtDate = StartDate + 5 ' Today is Thursday - go to Tuesday
Case 6
nxtDate = StartDate + 4 ' Today is Friday - go to Tuesday
Case 7
nxtDate = StartDate + 3 ' Today is Saturday - go to Tuesday
End Select

sSQL = "SELECT * FROM QueryCases WHERE (QueryCases.StartDate) >="& nxtDate & ";"

Me![ViewCasesSubform].Form.RecordSource = sSQL

End Sub
Jan 17 '08 #2
missinglinq
3,532 Expert 2GB
For clarification purposes, when you say "with a StartDate of next Tuesday and onward" do you mean

from tomorrow onward, if today is Monday

or

from Tuesday of next week and onward?

Tuesday of next week, for instance would be:

(date + (7 - Weekday(date, 3)) + 1)

Linq ;0)>
Jan 17 '08 #3
Thanks for the reply. I mean from Tuesday of next week and onward. The code above worked great!
Thanks
Jan 17 '08 #4
missinglinq
3,532 Expert 2GB
QueryCases.SatrtDate > (date + (7 - Weekday(date, 3)) + 1)

Linq ;0)>
Jan 17 '08 #5

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

Similar topics

2
by: raj chahal | last post by:
Hi there, I'm creating a access database for 'events'. I have created a field for 'date of event', the asp then checks if this date has lapsed, if so it doen't show the event. All works fine....
52
by: Andy Dingley | last post by:
I'm using this at present: <p title="Publication date" ></p> Works fine on screen, but Fangs/Jaws just reads it as "left bracket twenty-eight slash zero slash two thousand five fifteen colon...
3
by: Steve | last post by:
I have a people table of about 25 fields. The table is initially created each year from 5 different sources. The records from each source are appended to the people table. Any person may be in one...
1
by: Kathie G via AccessMonster.com | last post by:
Hello, I have a delima that I am not sure how to resolve. Records get entered manually or through an import. The records contain, RecordID, Client ID, Specimen Date, Visit Date, Client DOB, and...
17
by: Justin Emlay | last post by:
I'm hopping someone can help me out on a payroll project I need to implement. To start we are dealing with payroll periods. So we are dealing with an exact 10 days (Monday - Friday, 2 weeks). ...
5
by: Elainie | last post by:
I need to get the dates between now and next week but using Now and Next week not any specific dates... Please help, going mad... Elaine
7
by: john | last post by:
In my form I have a master table and a details table linked 1xM. I can search through the whole parent table but I also like to be able to search through the child table fields to find parent...
11
by: jennifersalcido | last post by:
Hello All, I am working with two tables that contain inventory data: 1) INVENTORY contains item_number, description, etc. This data is relatively straight-forward, one record per item_number....
5
by: Greg (codepug | last post by:
I have a table that contains a field called RDATE (reminder date). Dates are optionally entered to remind a user of an upcoming event. I have a reminder button that launches a popup form, and a...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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
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...
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...

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.