|
-
Aug 1st, 2006, 09:06 AM
#1
Thread Starter
Fanatic Member
-
Aug 1st, 2006, 09:18 AM
#2
Re: MSAccess Dateadd function
Try showing us the full query, so we can understand better.
-
Aug 1st, 2006, 09:25 AM
#3
Thread Starter
Fanatic Member
-
Aug 1st, 2006, 09:35 AM
#4
Re: MSAccess Dateadd function
Erm.. could you show us the SQL instead please! (very few of us use that kind of interface)
-
Aug 1st, 2006, 09:37 AM
#5
Thread Starter
Fanatic Member
Re: MSAccess Dateadd function
this is the sql view
SELECT Date.crew_schedule_date, Date.crew1, Date.crew2
FROM [Date]
WHERE (((Date.crew_schedule_date)=DateAdd("d",7,[crew_schedule_date])));
Thanks
** HOLLY ** 
-
Aug 1st, 2006, 09:45 AM
#6
Re: MSAccess Dateadd function
Oooh.. I just noticed that your table is called Date - that is a very bad idea, as it is a reserved word (which I'll actually use below!). It is likely to cause issues for you, and should really be changed to something different (possibly CrewDates).
You haven't specified what week of data you want (such as from/to certain dates, etc), but this will give the week starting today (untested):
SELECT Date.crew_schedule_date, Date.crew1, Date.crew2
FROM [Date]
WHERE (((Date.crew_schedule_date) Between Date And DateAdd("d",7,Date)));
-
Aug 1st, 2006, 09:56 AM
#7
Thread Starter
Fanatic Member
-
Aug 1st, 2006, 10:52 AM
#8
Hyperactive Member
Re: MSAccess Dateadd function
Hi Holly;
Based on your original post I assume that you want to be able to look at the crew schedule for a given week. If that is the case then the function you should consider using is DatePart.
I've created a sample query that you can cut and paste into your database. I've changed your table name to CrewSchedule. The query asks you to enter any date in the week and then returns the schedule for that week.
VB Code:
SELECT CrewSchedule.Crew_Schedule_date, CrewSchedule.Crew1, CrewSchedule.Crew2
FROM CrewSchedule
WHERE (((DatePart("ww",[Crew_Schedule_date]))=DatePart("ww",[Enter any date in week])));
I hope this is helpful to you.
-
Aug 1st, 2006, 11:33 AM
#9
Re: MSAccess Dateadd function
 Originally Posted by holly
I changed the table name as you stated and tried your sql as below
You changed the Where clause, it was actually meant to be Date (which returns the current date) rather than your field (which you were comparing to itself!), ie:
Code:
WHERE (((CrewDate.crew_schedule_date) Between Date And DateAdd("d",7,Date)));
However, LinXG's method may well be better for you - it depends how you define a week tho (7 days from today, or from a certain day of the week).
-
Aug 1st, 2006, 07:01 PM
#10
Frenzied Member
Re: MSAccess Dateadd function
Basically, never use reserved words in for table, field, query, etc., names. I deal with a lot of legacy dbs which have a lot of this going on, and it's a pain in the ass.
In Access, you can do this if you enclose the name in brackets, same as you would if you did the also bad practice of putting spaces in names, but it's really a heck of a lot easier to just name things appropriately to start with.
The convention I use is to start all tablenames with tbl (tblFoo), fields with fld (fldFoo), queries with qry (qryFoo), etc. Then you can name a table tblDate, for example, and when you refer to it in code, there'll be no question as to what you're referring to, and no conflict with reserved names.
If you have a query and you don't want the column heading of "fldFoo", in your SELECT statement use "SELECT fldFoo AS IDontWantNamefldFoo FROM tblFoo", or whatever you want the result to be called.
And as si wrote, not many programmers use the Access drag & drop query interface. It's okay if you don't do many queries, and they're simple ones, but SQL view is really the best way to go. Clearer, more control. Also necessary in almost every db outside Access.
Tengo mas preguntas que contestas
-
Aug 2nd, 2006, 03:13 AM
#11
Re: MSAccess Dateadd function
try the following:
Code:
SELECT [Date].[crew_schedule_date], [Date].[crew1], [Date].[crew2]
FROM [Date]
WHERE (((Date.crew_schedule_date) Between now And now+7
I noticed you changed the table name - so reflect that in the above as well. Hope you can get it working.
Note: function now includes time... You may need to use : cdate(format(now,'dd mmm yyyy')) to get just the date.

*edit* NOTE: square brackets put around fields and table names. So if you want the function do not use square brackets.
Last edited by Ecniv; Aug 2nd, 2006 at 03:41 AM.
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Aug 2nd, 2006, 03:15 AM
#12
Thread Starter
Fanatic Member
Re: MSAccess Dateadd function
Si,
I changed the SQL back...and now it asks me to input a date...how can I get it to automatically read todays date...I no I can use the Now() or date function..
SQL:
SELECT DMCF_CREW_SCHEDULE_Adm.crew_schedule_date, DMCF_CREW_SCHEDULE_Adm.crew1, DMCF_CREW_SCHEDULE_Adm.crew2
FROM DMCF_CREW_SCHEDULE_Adm
WHERE (((DMCF_CREW_SCHEDULE_Adm.crew_schedule_date) Between [Date] And DateAdd("d",7,[Date])));
Thanks very much!!
** HOLLY ** 
-
Aug 2nd, 2006, 05:43 AM
#13
Re: MSAccess Dateadd function
Did I have square brackets around Date in my where clause? 
The reason I didn't is because I was using the function Date (to return todays date), rather than a badly named field/table.
-
Aug 2nd, 2006, 07:11 AM
#14
Thread Starter
Fanatic Member
-
Aug 2nd, 2006, 07:17 AM
#15
Re: MSAccess Dateadd function
Good stuff, I'm glad to help. 
As you have the answer, could you please do us a little favour, and mark this thread as Resolved?
(this saves time reading for those of us who like to answer questions, and also helps those who search to find answers)
You can do this by clicking on "Thread tools" just above the first post in this thread, then "Mark thread resolved".
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|