Solved

query access database..

Posted on 2006-07-04
8
353 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…

746 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