Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Report pulling by day of the week?

Status
Not open for further replies.

CTOROCK

Programmer
May 14, 2002
289
US
I am adding days to dates Is there a better way to do it that the way I am doing it? I have a command button that writes in the day of the date in the table. Can I do it from a query?


Private Sub CmdAddDays_Click()
Dim DBData As Database
Dim Rst As Recordset
Dim DtDate As Date
Dim StrDay As String
Dim StrRecCount As String
Set DBData = OpenDatabase("call center app.mdb")

Set Rst = DBData.OpenRecordset("MasterCopy", dbOpenDynaset)
StrRecCount = Rst.RecordCount

Rst.MoveFirst

Do Until Rst.EOF


DtDate = Rst.Fields("Date").Value
StrDay = WeekDay(DtDate, vbMonday)

Dim StrDayWk As String
If StrDay = "1" Then
StrDayWk = "Monday"
ElseIf StrDay = "2" Then
StrDayWk = "Tuesday"
ElseIf StrDay = "3" Then
StrDayWk = "Wednesday"
ElseIf StrDay = "4" Then
StrDayWk = "Thursday"
ElseIf StrDay = "5" Then
StrDayWk = "Friday"
ElseIf StrDay = "6" Then
StrDayWk = "Saturday"
ElseIf StrDay = "7" Then
StrDayWk = "Sunday"
End If
Rst.Edit
Rst.Fields("Day") = StrDayWk
Rst.Update
Rst.MoveNext

Loop


Rst.Close


End Sub
"The greatest risk, is not taking one."
 
Run an update query. The update portion of the field "Day" would be (make sure you have the "Date" field as well that you're basing off of):

IIf(Weekday(Date)=1,"Monday",IIf(Weekday(Date)=2,"Tuesday",IIf(Weekday(Date)=3,"Wednesday",IIf(Weekday(Date)=4,"Thursday",IIf(Weekday(Date)=5,"Friday",IIf(Weekday(Date)=6,"Saturday","Sunday"))))))

Enjoy!
Roy McCafferty
aka BanditWk

Las Vegas, NV
roy@cccamerica.org
RLMBandit@aol.com (private)

"I do this because I know I can and I'm bored at work - no need to send flowers, wine, dinner, or coffee... Just send me a smile to show me that I've helped." ~ Roy McCafferty, seen on a corne
 
It says data type mismatch. Do you know why?
Will this overwrite my Date field? I'm not familiar with Update Queries. Can you please explain a little more? sorry but thanks!

eric

"The greatest risk, is not taking one."
 
I got it, I just substitutd the "" for []... But isn't this the same thing as my button? don't I have to run it every time like my button? what's the differece of advantage?
Thanks! "The greatest risk, is not taking one."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top