No data showing in query

L

lmd

I am new to Access and am using Access 2007.
I wanted to create a query to bring data together from several tables to
complete forms and form letters.
I used the Query Wizard to create a query which selected data from the
different tables. It worked fine and I was able to complete a form in Word.
I have now used the the same process using the same tables for a couple of
other queries but now there is no data in those datasheets. Anything I'm
missing here? Thanks.
 
P

Philip Herlihy

There are three ways of creating a query. The query wizard, which you've
used, is at one end of the "easy/hard" scale. At the other is writing the
"SQL" code by hand in SQL view (often a good idea to view the SQL however
you create your query.) In the middle is the query designer, and it sounds
like that's where you ought to be working now.

This website gives you an introduction to queries including the designer:
http://office.microsoft.com/trainin...ID=RC102919041033&CTT=6&Origin=RC102919041033
(may wrap lines, re-join with no spaces).

If you open the designer, you first have to add tables. Try adding just
one. Drag a few fields onto the matrix, and view the results. Try adding a
sort value (ascending or descending) and take it away again. Try adding a
criterion: if you want names that begin with a P, then put into the
Criterion row, under the appropriate field:
Like "P*"
Then take it out again - just practice.

Then add one more table. I'm assuming here that your tables are right, and
that there is at least one relationship (typically where records in one
table contain a "key" reference to records in another. That's a pretty big
assumption, of course.

Add tables so that you have both sides of one of your relations. If you've
set up the relationship in the Relationships window, then the query designer
will pick that up; otherwise you have to drag the appropriate field from one
table to the other in the view at the top of the query designer.

You'll only get those records where there's a match. So, if you have tables
for Customer and for Order, where one customer may place many orders, you'd
typically include the customerID (the customer "key") in each Order record
(as a "foreign key"). You may be interested in orders from customers whose
name begins with P, so you've added the criterion mentioned above. But if
no customers whose name begins with a P has placed an order, you'll
(rightly!) get no results. It's worth mentioning that you can change the
properties of the relationship so that it lists all customers and their
orders, including those with none. Double-click the relationship line to
see how to do this (it's called an Outer Join as opposed to the normal Inner
Join).

When I'm having trouble with a query, I build it up in the designer by
stages. I list one table, and then another, adding fields one at a time so
I can see what records I'm getting. If you're unfamiliar with the query
designer, open an existing query in Design View - the designer is what comes
up Copy an existing query, and then fool about with the copy in the
designer to see what you can do.

If you still end up stuck, view your query in SQL View. Copy the text you
see there, and post it here.

HTH

Phil, London
 
S

Steve

Keep in mind that when a query includes multiple tables, each table must
contain one or more records that contain the join field for any records to
be returned by the query. For example, if you have a TblCustomer with
CustomerID and TblInvoice with CustomerID and both tables are include in a
query where the tables are joined on CustomerID. If there are no invoice
records in TblInvoice although there are numerous customer records in
TblCustomer, the query will not return any records.

Steve
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top