?
Solved

query access database..

Posted on 2006-07-04
8
Medium Priority
?
399 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

801 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