?
Solved

query access database..

Posted on 2006-07-04
8
Medium Priority
?
405 Views
Last Modified: 2012-06-27
Hi Experts,

I am pretty new to access database and my database got one table called salesinfo..

I need to query this table and i had hard time in doing so.

In sql server we had query analyser and enterprise manager so we can select table and can write query so it will display the result of the query in a grid..

In access i have seen only 2 options 1)Create query in Design view
                                                    2)Create query by using wizard..

Tottaly lost...

Secondly  one of my table field is PrintDate

                                                                       PrintDate
                                                                       09/11/2006
                                                                       11/09/2006

Since my user workstation dateformat can vary like  DD-MM-YYYY , MM-DD-YYYY.

I need to fetch all the 2006 records, so query need to omit for 09/11/ -- need check yyyy is 2006 or not if yes display
the result in a grid ..

How should i write a query and what is the query for the above mentioned scenario..





0
Comment
Question by:nyee84
8 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 17040441
U can use functions like YEAR

select  * from yourtable where Year(PrintDate) = 2006

0
 
LVL 65

Assisted Solution

by:rockiroads
rockiroads earned 400 total points
ID: 17040446
If u have a form which is bounded to the table

u can use Form_Current to determine this

say u had a field called PrintDate on your form and a checkbox called chkBox

private sub Form_Current()
    if year(printdate) = 2006 then chkBox.Value = True else chkBox.Value = False
end sub



Now what does 2006 refer to, current year? in that case, use Now()
e.g.
year(Now()) returns 2006

private sub Form_Current()
    if year(printdate) = year(Now()) then chkBox.Value = True else chkBox.Value = False
end sub


0
 
LVL 14

Assisted Solution

by:bluelizard
bluelizard earned 200 total points
ID: 17040447
1)
well, if you write the query in the design view, and then switch to "datasheet view" (by clicking on the top left icon or by selecting the menu item "query > run"), the results are indeed shown in a grid, i.e., like a table. is that what you mean?

so, for writing "normal" queries, the design view is probably the method of choice.

2)
is PrintDate a text field or a date field?  how should the query decide when to interprete it as dd-mm and when as mm-dd?

3)
what's the goal of your query? list all rows that have print date other than 2006?


--bluelizard
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 35

Accepted Solution

by:
Raynard7 earned 600 total points
ID: 17040454
If you go to the query browser - it has an option to have a visual query creator or to select SQL and write in teh query yourself.

Go to design view - on left of the tool bar there is a drop down list - there are three things on it - select SQL.

if PrintDate is a date field you can use rockiroads solution or you can use
select  * from yourtable where PrintDate > dateserial(2006,01,01)
If you use dateserial it creates the date in order that is specified by the dateserial function which is not date setting specific.
0
 
LVL 3

Assisted Solution

by:atherh
atherh earned 400 total points
ID: 17040745
Put In Module
===================

Global Const JetDateTimeFmt = "\#mm\/dd\/yyyy hh\:nn\:ss\#;;;\N\u\l\l"
Global Const JetDateFmt = "\#mm\/dd\/yyyy\#;;;\N\u\l\l"
Global Const JetTimeFmt = "\#hh\:nn\:ss\#;;;\N\u\l\l"


Go to design view - on left of the tool bar there is a drop down list - there are three things on it - select SQL.

============
'If you are passing from form

select  * from yourtable where Year(PrintDate)=" & Year(Format$(CboDate, JetDateTimeFmt))

other wise with rockiroads solution u can try in quote

select  * from yourtable where Year(PrintDate) = '2006'
0
 
LVL 44

Assisted Solution

by:Arthur_Wood
Arthur_Wood earned 400 total points
ID: 17041538
Open the Query Builder using Create Query in Design View.  You can then eitehr

1) Select the Table (or Tables) that you wnat to use in the query, then click Done
    then select the fields that you want to use from that (those) table(s)
    Then click the Red ! on the tool bar, to execute the query

2)  do NOT seledt any tables, but simple click the Done button on the Select Table dialog
     then click on the button labelled SQL (immediately below the File Menu item on the Menu bar.
     Now you can enter the full SQL for whatever query you want to execute.  Then click the red ! to execute the query

eiterh way, when you close the Querry builder, you will be asked if you want to save the Query that you have just built.  If you choose to save it, you can then supply a Name for the saved query.

AW
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17041585
Here is a tutorial for u
The site may be useful for u as it contains other info as well regarding Access
http://www.functionx.com/access/Lesson16.htm
0
 

Author Comment

by:nyee84
ID: 17042175
Hi Experts,

Thanks for all the comments..

0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question