Microsoft Access Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft Access Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old January 9th, 2004, 08:23 PM
OneRedLT4's Avatar
OneRedLT4 OneRedLT4 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: California
Posts: 299 OneRedLT4 User rank is Corporal (100 - 500 Reputation Level)OneRedLT4 User rank is Corporal (100 - 500 Reputation Level)OneRedLT4 User rank is Corporal (100 - 500 Reputation Level)OneRedLT4 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 20 h 50 m 39 sec
Reputation Power: 7
Send a message via AIM to OneRedLT4 Send a message via Yahoo to OneRedLT4
Question Date help

I feel like this is one I should be able to figure out, but I keep drawing a blank. In my DB I have a query that has a date field. I'd like to create a macro or criteria within the query that, when run, returns only those records that fall within the previous Sunday through Saturday period. In otherwords, if it's Tuesday, for example, it will return all records from Sunday up to the previous Saturday. Any ideas? I keep fiddling around with date function and Instr functions, but I think I'm going around in circles.
Thanks.
Jim

Reply With Quote
  #2  
Old January 11th, 2004, 06:02 PM
TBÁrpi's Avatar
TBÁrpi TBÁrpi is offline
Lazy User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Hungary, Europe
Posts: 337 TBÁrpi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 5 m 5 sec
Reputation Power: 5
Send a message via MSN to TBÁrpi Send a message via Yahoo to TBÁrpi Send a message via Skype to TBÁrpi
What you can see below is a function that returns the Monday's date of a week in which a given date is.

Quote:
Public Function GetMondayDate(dtmDate As Date) As Date
GetMondayDate = dtmDate - (Weekday(dtmDate, vbMonday) - 1)
End Function


For example, if dtmDate is 13/01/2004 then it will return 12/01/2004.

You can play with this function to return any day's date for you.
__________________
BRegs,
TBÁrpi
"I can only show you the door. You're the one who has to walk through it."

Reply With Quote
  #3  
Old January 12th, 2004, 05:24 PM
OneRedLT4's Avatar
OneRedLT4 OneRedLT4 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: California
Posts: 299 OneRedLT4 User rank is Corporal (100 - 500 Reputation Level)OneRedLT4 User rank is Corporal (100 - 500 Reputation Level)OneRedLT4 User rank is Corporal (100 - 500 Reputation Level)OneRedLT4 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 20 h 50 m 39 sec
Reputation Power: 7
Send a message via AIM to OneRedLT4 Send a message via Yahoo to OneRedLT4
Thanks, but if I'm reading it correctly, the dtmDate variable still has to "fed" a date that is a starting point for the function. So as every day that passes the outcome is one date later, which won't be what I need.
What about a parameter query that asks for a week number, which would be inserted into a funtion that returns the appropriate Sunday-Saturday dates? For example, user puts in 1 for the week number and the query returns all records with dates Jan 4th - Jan 10th. Any ideas?
Thanks again.
Jim

Reply With Quote
  #4  
Old January 13th, 2004, 10:40 AM
TBÁrpi's Avatar
TBÁrpi TBÁrpi is offline
Lazy User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Hungary, Europe
Posts: 337 TBÁrpi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 5 m 5 sec
Reputation Power: 5
Send a message via MSN to TBÁrpi Send a message via Yahoo to TBÁrpi Send a message via Skype to TBÁrpi
Use DatePart function to return the week number where specified date is.
DatePart returns a Variant (Integer) containing the specified part of a given date.
If you wish to return the week number then you need to use "ww" as the first actual parameter.

Then you can select the records returning a given week number:

dim MySQL as string
MySQL="select * from tblTable where datepart("ww",DateField_in_tblTable,vbusesystem,vbusesystem)=" & val(inputbox("Enter a week number: "))
docmd.runsql MySQL

Check Help for more about DatePart function.

Last edited by TBÁrpi : January 13th, 2004 at 10:42 AM.

Reply With Quote
  #5  
Old January 14th, 2004, 08:06 PM
OneRedLT4's Avatar
OneRedLT4 OneRedLT4 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: California
Posts: 299 OneRedLT4 User rank is Corporal (100 - 500 Reputation Level)OneRedLT4 User rank is Corporal (100 - 500 Reputation Level)OneRedLT4 User rank is Corporal (100 - 500 Reputation Level)OneRedLT4 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 20 h 50 m 39 sec
Reputation Power: 7
Send a message via AIM to OneRedLT4 Send a message via Yahoo to OneRedLT4
Thanks again, I'm assuming that this needs to be put into the VBA code (I did it as a click event to a cmd button to get it working), but Access keeps throwing up an error (Expect end of statement) highlighting words after quotes when clicking off that line of code. I can't use variables and such in SQL view of queries, right? Or as report data source? I'm thinking even if I get this working, the user clicks the button, input box pops up, number goes in, and a data sheet view of the results shows. Wouldn't this have to be saved as a query somewhere to design a report for it? The goal is to have a button, that when clicked, prints a Sunday-Saturday time and attendance records for the week choosen.
The more I think of this the more I think my boss will just have to use a "dual parameter" query (beginning date and ending date).

Reply With Quote
  #6  
Old January 15th, 2004, 02:30 PM
TBÁrpi's Avatar
TBÁrpi TBÁrpi is offline
Lazy User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Hungary, Europe
Posts: 337 TBÁrpi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 5 m 5 sec
Reputation Power: 5
Send a message via MSN to TBÁrpi Send a message via Yahoo to TBÁrpi Send a message via Skype to TBÁrpi
See the sample database I designed for you.

Open frmButton and click the button. It brings up an input box that prompts the user for a week number. When the user clicks OK, the subform will show only the records with date in that week.

If you wish to execute the code step by step then place a breakpoint to the OnClick event and press F8 to step to the next statement.

Play with it, investigate. I am sure you'll find your way.
Attached Files
File Type: zip oneredlt4.zip (34.3 KB, 203 views)

Reply With Quote
  #7  
Old January 16th, 2004, 03:05 PM
OneRedLT4's Avatar
OneRedLT4 OneRedLT4 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: California
Posts: 299 OneRedLT4 User rank is Corporal (100 - 500 Reputation Level)OneRedLT4 User rank is Corporal (100 - 500 Reputation Level)OneRedLT4 User rank is Corporal (100 - 500 Reputation Level)OneRedLT4 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 20 h 50 m 39 sec
Reputation Power: 7
Send a message via AIM to OneRedLT4 Send a message via Yahoo to OneRedLT4
Thanks, I don't know why it didn't work before, unless I didn't see a typo. I've been messing around with it for a couple of hours, trying to use your example to feed a report, but the date and names fields come up with "#Name?". Here's what I've got...

Private Sub btnWeekly_Click()
Dim MySQL As String
Dim stDocName As String

stDocName = "rptWeeklyTA"

MySQL = "SELECT tblEmployeeInfo.EmpID, tblEmployeeInfo.LastName, tblEmployeeInfo.FirstName, tblViolation.Date, tblViolation.Violation, tblViolation.[T/A] FROM tblEmployeeInfo INNER JOIN tblViolation ON tblEmployeeInfo.EmpID = tblViolation.EmpID where DatePart('ww',tblViolation.Date,0,0)=" & Val(InputBox("Enter a week number:"))

'rptWeeklyTA.Report.RecordSource = MySQL
DoCmd.OpenReport stDocName, acPreview

'sfrmAllMIFEquipment1.Form.Requery
End Sub

When I run the line above the DoCmd not as a comment, it throws up a 424 error. I'm getting close, I think, the report tries to open. I even changed the control source of the text boxes to tblName.FieldName format, but didn't make a difference. Thanks again for the input.
Jim

Reply With Quote
  #8  
Old January 16th, 2004, 04:32 PM
TBÁrpi's Avatar
TBÁrpi TBÁrpi is offline
Lazy User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: Hungary, Europe
Posts: 337 TBÁrpi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 5 m 5 sec
Reputation Power: 5
Send a message via MSN to TBÁrpi Send a message via Yahoo to TBÁrpi Send a message via Skype to TBÁrpi
It's something with names in your report. I mean the field names where the controls of your report refer to.

Post your DB, but compress and zip it before posting. I will have a look at it.

Reply With Quote
  #9  
Old January 16th, 2004, 06:24 PM
OneRedLT4's Avatar
OneRedLT4 OneRedLT4 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: California
Posts: 299 OneRedLT4 User rank is Corporal (100 - 500 Reputation Level)OneRedLT4 User rank is Corporal (100 - 500 Reputation Level)OneRedLT4 User rank is Corporal (100 - 500 Reputation Level)OneRedLT4 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 20 h 50 m 39 sec
Reputation Power: 7
Send a message via AIM to OneRedLT4 Send a message via Yahoo to OneRedLT4
Wouldn't attach. PM'd you with it's location.... Hope it works.

Reply With Quote
  #10  
Old January 16th, 2004, 09:13 PM
OneRedLT4's Avatar
OneRedLT4 OneRedLT4 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: California
Posts: 299 OneRedLT4 User rank is Corporal (100 - 500 Reputation Level)OneRedLT4 User rank is Corporal (100 - 500 Reputation Level)OneRedLT4 User rank is Corporal (100 - 500 Reputation Level)OneRedLT4 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 20 h 50 m 39 sec
Reputation Power: 7
Send a message via AIM to OneRedLT4 Send a message via Yahoo to OneRedLT4
Ok, hopefully I didn't get rid of anything you need. The T/A Violations form has a button labeled Weekly T/A. That's the one I'm fighting with. In the VBA code, I forgot to undo the experimentations, like brackets around the field names and the "DoCmd.openQuery..." line. Once those are back/gone, the report opens with what appears as no record source. I think it's missing a simple line of code.
Jim

Last edited by OneRedLT4 : January 16th, 2004 at 09:18 PM.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft Access Help > Date help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway