Solved

Excel VBA -To say Current Week

Posted on 2006-06-26
7
298 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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 AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to create a duplicate finder Application 9 121
String manipulation in Visual Basic 7 62
MS Access Search and Replace Using VBA 6 71
Visual Studio 2005 text editor 10 38
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

772 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