Solved

Excel VBA -To say Current Week

Posted on 2006-06-26
7
302 Views
Last Modified: 2008-03-10
This Excel VBA
 Is there any way in this line to say current week, where I do not have to change the date every week?

Src = Src & "WHERE Table1.RecDt Between #6/26/2006# And #6/30/2006# "

Any help would greatly be appreciated!
///////////////////////////////////////////////////////

Src = "SELECT Sum(Table1.LoanAmt) AS SumOfLoanAmt "     '<--- space added to
Src = Src & "FROM Table1 " 
Src = Src & "WHERE Table1.RecDt Between #6/26/2006# And #6/30/2006# "
Src = Src & "GROUP BY Table1.[AS400 ID] "
Src = Src & "HAVING Table1.[AS400 ID]) = " & TradeLimit.ComboBox1.Value

0
Comment
Question by:ca1358
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 20

Expert Comment

by:alainbryden
ID: 16984620
If you type
Month(Date)
Year(Date) and
Day(Date)

(you get the idea) you can get individual segments of the current date / time.

Alternatively you can say

Src = Src & Format(Now, "MM/DD/YYYY")

0
 
LVL 35

Expert Comment

by:mvidas
ID: 16984632
Hi ca1358,

Using the Weekday function, we can determine which day of the week it is, and subsequently which day the corresponding monday/friday is.  I wasn't sure how you wanted the weekends handled, so if it doesnt do as you wish for those let us know and we can modify it:

 Src = "SELECT Sum(Table1.LoanAmt) AS SumOfLoanAmt "     '<--- space added to
 Src = Src & "FROM Table1 "
 Src = Src & "WHERE Table1.RecDt Between #" & Date - Weekday(Date, 2) + 1 & _
       "# And #" & Weekday(Date, 2) + 5 & "# "
 Src = Src & "GROUP BY Table1.[AS400 ID] "
 Src = Src & "HAVING Table1.[AS400 ID]) = " & TradeLimit.ComboBox1.Value

Matt
0
 
LVL 35

Accepted Solution

by:
mvidas earned 500 total points
ID: 16984680
Stupid me, made a copy/paste error.  The middle line should be (added "Date - ")

 Src = Src & "WHERE Table1.RecDt Between #" & Date - Weekday(Date, 2) + 1 & _
  "# And #" & Date - Weekday(Date, 2) + 5 & "# "

Matt
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 16984681
Hi ca1358,

Assuming the "week" begins Monday and ends Friday, replace the line:

Src = Src & "WHERE Table1.RecDt Between #6/26/2006# And #6/30/2006# "

with:

Src = Src & WHERE Table1.RecDt Between #" & Format(Date - Weekday(Date, vbMonday) + 1, "m/d/yyyy") & _
    "# And #" & Format(Date - Weekday(Date, vbMonday) + 5, "m/d/yyyy") & "# "

Regards,

Patrick
0
 
LVL 35

Expert Comment

by:mvidas
ID: 16985049
Great minds, Patrick...

Glad to help, ca1358!
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 16985469
Matt,

> Great minds, Patrick...

Yeah, but what's our explanation?

:)

Regards,

Patrick
0
 
LVL 35

Expert Comment

by:mvidas
ID: 16985524
Theres an exception to every rule..  Great minds think alike, and so do ours!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

687 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question