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  dBforums > PC based Database Applications > Microsoft Excel > Query range: Within prior Month's first and last day

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-03-04, 13:06
paulzak paulzak is offline
Registered User
 
Join Date: May 2004
Posts: 54
Query range: Within prior Month's first and last day

I have a query that I need to pull records added during the prior month. (The table stores date of each new record.) So I'd like for the user to NOT have to add a date range each month (more work and not goof proof) when he/she runs the query. Does anyone know the code I'd use in the query to set the range based on "between" the first and last days (including those dates) for the prior month? Sounds simple but...
Reply With Quote
  #2 (permalink)  
Old 05-04-04, 08:04
MikeTheBike MikeTheBike is offline
Registered User
 
Join Date: Apr 2004
Location: Derbyshire, UK
Posts: 714
Query dates

I am not sure if you want a worksheet function or a VB cide solution but for the worksheet use

=EOMONTH(NOW(),-1) for the the end date (last day of previouse month)

and

=EOMONTH(NOW(),-2)+1 for the start date; (first day of previous month)


In code the following will do the same job

Sub SetDates(ByRef dStart As Date, ByRef dEnd As Date)

dEnd = DateAdd("d", -Day(Date), Date)

dStart = DateAdd("d", -Day(dEnd), dEnd) + 1

End Sub

Hope this coveres it

MTB
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On