Solved

query access database..

Posted on 2006-07-04
8
362 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 100 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 50 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
 
LVL 35

Accepted Solution

by:
Raynard7 earned 150 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 3

Assisted Solution

by:atherh
atherh earned 100 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 100 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

930 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now