February 25, 2021
Hot Topics:

Visual Basic Database Tutorial - Part 2

  • By Karl Moore
  • Send Email »
  • More Articles »

Do you want the bad news or the good news?

Hmm, bad news first. I thought, being a personal friend of mine, you ought to know that I'm actually listening to a Barry Manilow CD as I type. I know, I know... but some of his songs really aren't that bad. Oh, and I don't mind Chris Rea neither.

Oh boy, I'm never going to get that date I wanted back in the Beginning Visual Basic tutorial, am I?

Anyway, enough of that - here's a bit of good news. Access has a built-in translator that allows you to design those SQL statements using a really groovy user interface - and yes, that means you never really have to learn about SQL, you idle person you.

Start Microsoft Access and open the Nwind.mdb database we used in the last section. Click on the Queries tab, then select Design View and click OK. When prompted to add a table, select Customers, click Add, then Close.

Your screen should look something like this:

Despite all those strange asterisk symbols and criteria boxes lying all over the place, you'll soon get the hang of using this 'query' builder.

Top Tip: If you have a sore throat, try drinking warm honey mixed with fresh lemon juice.

Double click on the ContactName field in the 'Customers' table. Then double click the ContactTitle field. They should both appear on your screen, as so:

You've just designed your first query. You're asking the database "Show me everything in the 'ContactName' and 'ContactTitle' fields in the Customers table" - just as we did in the last section.

Click on View, Datasheet View. Your screen should look something like this:

Now click on View, SQL View. You should see this:

SELECT Customers.ContactName, Customers.ContactTitle
FROM Customers;

"What??", I hear you cry. Yes, with just a couple of clicks you have automatically generated the SQL statements we poured over in the last section.

Our original statement looked like this:

Select ContactName, ContactTitle from Customers

But both statements - the manual SQL and Access-generated SQL - do exactly the same thing. So when generating more complex queries, you might as well head straight for Access... and do it the easy way!

Page 7 of 8

This article was originally published on November 20, 2002

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date