Simple Access SQL Query?

I

ihatecomputers

Hi,

Can someone kindly post some example code for a SQL query?

I have a table named Foo, with text fields foo and bar, and a numeri
field named type. At the moment, Access will display all of the dat
in my table in my three field form. I would like to be able to press
button, and perform a SQL query on the table. Something like: "SELEC
* FROM Foo WHERE type = 2;"

I've written some VB code to cause a button to do this, and while i
apparently runs without error, it also runs without changing the recor
data.

I've been searching the web to no avail, trying to find out how to ge
this to work. It should be simple enough, right?

Thanks,

Mike
(
 
K

Kevin Sprinkel

There is nothing wrong with your SQL query syntax, but
executing this query does NOT make it the source for your
form. This is controlled by the RecordSource property.
So, after executing your query, your form continues to
display all the source records defined by this property.

The easiest way to do what you're after is to apply a
filter. This can be done without programming by using the
Filter By Form menu button to enter the criteria, and then
the Filter menu button to filter the records. Both are on
the Form View toolbar.

You can also add command buttons to your form to duplicate
this functionality. The easiest way is to use the wizard
and select the operations from its Form Operations menu.

After applying the filter, check the form's Filter
property to see what Access wrote there.

Re: learning Access SQL, apart from many good books
available, one simple way is to construct queries in Query
Design view, and after verifying your results, change to
SQL View to see what SQL code Access wrote. Be aware,
however, that Access implements SQL slightly differently
than most other DB programs.

This strategy is also effective to learn Visual Basic for
Applications (VBA), i.e., use a wizard to construct the
code, and then study it. Once you're more advanced, don't
hesitate to use the wizard, either, it saves time!

HTH
Kevin Sprinkel
Can someone kindly post some example code for a SQL query?
I have a table named Foo, with text fields foo and bar,
and a numeric field named type. At the moment, Access
will display all of the data in my table in my three field
form. I would like to be able to press a button, and
perform a SQL query on the table. Something like: "SELECT
 
J

John Vinson

Something like: "SELECT
* FROM Foo WHERE type = 2;"

I've written some VB code to cause a button to do this, and while it
apparently runs without error, it also runs without changing the record
data.

A select query isn't DESIGNED to change any record data, just to
select it for display. What do you expect/want to change, and to what?
 

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