473,546 Members | 2,239 Online
Bytes | Software Development & Data Engineering Community
+ 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.Airl ineCode, tblflight1.Flig htnuminout, tblflight1.STA, tblflight1.Rout eFrom, tblflight1.STD, tblflight1.Rout eTo, tblflight1.Conf iguration, tblflight1.Equi pment, tblflight1.Prog ramIN, tblflight1.Rema rks, tblflight1.Arri valdate, tblflight1.Depa rturedate, tblflight1.Week start, tblflight1.Week end
FROM tblflight1
WHERE (((tblflight1.A rrivaldate)=Dat ePart("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",Da te(2))));
Apr 20 '07 #1
7 2814
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.Arri valdate==Weekda yName ;

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(sto red 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(sto red 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(sto red 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(sto red 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(sto red 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(sto red 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
9061
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 for. What is the equivalent SLQ code for the below statement which works in MS Access? Format(7,"00") Result: 07
3
2368
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 (tblInspections.InspDate Between #01/06/03# and #30/06/03#); but when I look at the result of this in teh QBE window, I get dates Between #06/01/03#...
4
8832
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 works and sometimes doesnt. When it doesnt, it gives me a 1004 "Method of Columns" of object variable failed error. My only guess is a timing...
2
1354
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 extension of the file name exclusively. So we have to look in the file itself using Vb .Net program code. By looking at the contents of the file using a...
12
2576
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 example: 21/05/2006
2
2387
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 portion of a phone call took. I need to be able to do some calculations based on these columns. The problem is when I run a query, let's say: SELECT...
37
3909
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 a function
0
895
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 that Grid Control so for that iam able Getting that Data Based on "Commaseparated"and "Tex" and As well "Stringformat" so here im using...
2
2183
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 text and the results are displayed in the list box(the search is done on the table which I copied from excel). Everything works fine as I want. The...
0
7504
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7694
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7947
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7461
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7792
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6026
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.