Solved

Excel VBA -To say Current Week

Posted on 2006-06-26
7
297 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now