473,465 Members | 1,915 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Format Datepart func to return specific rows based on datestored via qry to excel

20 New Member
I have an access table that outputs to excel using a query . However what I am trying to do is under the arrival date column specify a criteria based on the Datepart function that only displays output based on specific day of week.

I want query to check the stored date in the arrival column and based on that date that is examined by the date part function only return rows based on day of week .Here is my sql.



SELECT tblflight1.AirlineCode, tblflight1.Flightnuminout, tblflight1.STA, tblflight1.RouteFrom, tblflight1.STD, tblflight1.RouteTo, tblflight1.Configuration, tblflight1.Equipment, tblflight1.ProgramIN, tblflight1.Remarks, tblflight1.Arrivaldate, tblflight1.Departuredate, tblflight1.Weekstart, tblflight1.Weekend
FROM tblflight1
WHERE (((tblflight1.Arrivaldate)=DatePart("w",Date(2)))) ;

I keep getting an error can someone please point me in the right direction.
What I am trying to do in the where clause is to return dates based on arrivaldates for dayofweek monday

I am sure that I incorrectly formatting DatePart("w",Date(2))));
Apr 20 '07 #1
7 2794
MMcCarthy
14,534 Recognized Expert Moderator MVP
This will return all records where Weekday is the same as the current date.
Expand|Select|Wrap|Line Numbers
  1. SELECT tblflight1.AirlineCode, tblflight1.Flightnuminout, tblflight1.STA, tblflight1.RouteFrom, tblflight1.STD, tblflight1.RouteTo, tblflight1.Configuration, tblflight1.Equipment, tblflight1.ProgramIN, tblflight1.Remarks, tblflight1.Arrivaldate, tblflight1.Departuredate, tblflight1.Weekstart, tblflight1.Weekend
  2. FROM tblflight1
  3. WHERE Weekday(tblflight1.Arrivaldate)=Weekday(Date());
  4.  
Mary
Apr 21 '07 #2
tasmontique
20 New Member
This will return all records where Weekday is the same as the current date.
Expand|Select|Wrap|Line Numbers
  1. SELECT tblflight1.AirlineCode, tblflight1.Flightnuminout, tblflight1.STA, tblflight1.RouteFrom, tblflight1.STD, tblflight1.RouteTo, tblflight1.Configuration, tblflight1.Equipment, tblflight1.ProgramIN, tblflight1.Remarks, tblflight1.Arrivaldate, tblflight1.Departuredate, tblflight1.Weekstart, tblflight1.Weekend
  2. FROM tblflight1
  3. WHERE Weekday(tblflight1.Arrivaldate)=Weekday(Date());
  4.  
Mary
Thank you so much.
I read up on the weekday function but it is still not doing what I intended.Maybe it is not possible in a query that is being exported to excel.
I want to run a query that returns weekday based on the stored value in the table colum eg
SELECT*
FROM tblflight1
WHERE tblflight1.Arrivaldate==WeekdayName ;

I tried this but I get an error Datatype mismatch conversion
Apr 24 '07 #3
MMcCarthy
14,534 Recognized Expert Moderator MVP
Not sure exactly what you mean by this ...

Expand|Select|Wrap|Line Numbers
  1.  WHERE tblflight1.Arrivaldate==WeekdayName
Where are you getting WeekdayName from and what is it based on?
I assume Arrivaldate is an actual date.

Mary
Apr 24 '07 #4
tasmontique
20 New Member
I was trying to use the WeekdayName function.
However I realize that this WeekdayName function returns a String representation of a day given a number e.g.:

WeekdayName (3) would = Tuesday

My error is I am comparing Arrivaldate(stored table column date value) with basically nothing WeekdayName (3) .

I want to create a new expression in the query that finds out what Weekday Arrivaldate(stored table column date value ) is by using the WeekDay function and from there try to build query(criteria) that only returns specific weekday for Arrivaldate(stored table column date value).

I am clueless about how I would do this in sql.
Apr 25 '07 #5
MMcCarthy
14,534 Recognized Expert Moderator MVP
I was trying to use the WeekdayName function.
However I realize that this WeekdayName function returns a String representation of a day given a number e.g.:

WeekdayName (3) would = Tuesday

My error is I am comparing Arrivaldate(stored table column date value) with basically nothing WeekdayName (3) .

I want to create a new expression in the query that finds out what Weekday Arrivaldate(stored table column date value ) is by using the WeekDay function and from there try to build query(criteria) that only returns specific weekday for Arrivaldate(stored table column date value).

I am clueless about how I would do this in sql.
How are you deciding which ArrivalDate to base the weekday on for the criteria. Is the query for a report or what?
Apr 25 '07 #6
tasmontique
20 New Member
How are you deciding which ArrivalDate to base the weekday on for the criteria. Is the query for a report or what?
The query is for a "report" that is output to excel. The "report" will be based on a select statement that returns information in tblflight1

Which I have done. But presently the query just returns select * from tblflight1 right now into the spreadsheet.
I want to filter or base the query on the criteria of specific arrivaldates.

Initially I thought that if I designed a query that returns information from the table based on Weekday that is Sunday,Monday etc.
Then the arrivaldate column would be sorted based on that criteria.

However, I know think that it might be simpler to just modify an existing form that I have.
This form does a search where the user enters an arrivaldate in the textbox and it returns all the records based on arrivaldate.

I would like to just add a command button eg cmdprint.This cmdprint button would output the results to the preformatted excel spreadsheet based on the arrivaldate.

I know that I have to use vba to do this.
Can someone pretty please point me to a good tutorial to transfer info to a preformatted excel spreadsheet based on results filtered on a form ( by arrivaldate search results.)

Regardless Thanks for all your help thus far
Apr 25 '07 #7
MMcCarthy
14,534 Recognized Expert Moderator MVP
Try this ...
Expand|Select|Wrap|Line Numbers
  1. SELECT tblflight1.AirlineCode, tblflight1.Flightnuminout, tblflight1.STA,
  2. tblflight1.RouteFrom, tblflight1.STD, tblflight1.RouteTo,
  3. tblflight1.Configuration, tblflight1.Equipment, tblflight1.ProgramIN,
  4. tblflight1.Remarks, tblflight1.Arrivaldate, tblflight1.Departuredate,
  5. tblflight1.Weekstart, tblflight1.Weekend,
  6. WeekdayName(tblflight1.Arrivaldate)
  7. FROM tblflight1
  8. ORDER BY Weekday(tblflight1.Arrivaldate);
  9.  
Mary
Apr 25 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: tcumming | last post by:
Hi ... i'm sorry to hassle this user group but i have an urgent need for some code - i have tried and tried to find a solutionn elsewhere - but the problem is i don't really know what i am looking...
3
by: Gerry Abbott | last post by:
Hi all Im in Ireland, so date format is always dd/mm/yy. It trying use query as a filter for a recordset, containing a date field, SELECT tblInspections.InspDate FROM tblInspections WHERE...
4
by: BerkshireGuy | last post by:
I have the following Access code that exports to Excel, inserts a title, changes the color of the title, and then changes the format of several columns to currency. The following code sometimes...
2
by: RD | last post by:
We're picking up files on an FTP server using a vb.net program. We need to know if the file we pick up is an ASCII comma separated file or if it is in an Exel format without relying on the...
12
by: Rob Meade | last post by:
Hi all, Ok - I've come from a 1.1 background - and previously I've never had any problem with doing this: Response.Write (Session("MyDate").ToString("dd/MM/yyyy")) So, I might get this for...
2
by: galexyus | last post by:
I have an Access database for which I need to write reporting software. One of the tables has datetime columns such as RingTime, HoldTime, TalkTime, which are supposed to contain the time each...
37
by: jht5945 | last post by:
For example I wrote a function: function Func() { // do something } we can call it like: var obj = new Func(); // call it as a constructor or var result = Func(); // call it as...
0
by: pnarasimha | last post by:
Hai Friends , I have strucked with one problem in my Project , that is actually in my Project i had Grid control and User may Copy excel data from Excel file rows and paste into in...
2
by: NasirMunir | last post by:
I have created a table in access (copied from excel). Then I created a form which contains a text field and a list box. The text field is actually a look-up field, where a user can enter a searchable...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.