First, go to your form's design screen and open up the "Data" section on the toolbar. Select OleDbConnection and add one to your form. This object will contain the connection string for the database. Just set the ConnectionString property using the wizard you'll find in the drop-down box.
Next, go back to the toolbar and add an OleDbDataAdapter object. This is the connection between the database object and your program. Although there is a lot of functionality within this device, I've only used one part... to create Select queries. Go under the "SelectCommand" property, to "Connection"... and choose your OleDbConnection object from the list. Now you can put your SQL statement in
[YourAdapterObject].SelectCommand.CommandText = "SQL Statement Here"
Now... in your code, you do something like this:
Code:
Dim NewTable as New Data.DataTable()
Adapter.SelectCommand.CommandText = "SELECT ..."
Adapter.Fill(NewTable)
This fills "NewTable" with the results of the query. You can access it like this:
Code:
x = NewTable.Rows(n)("Fieldname here")
You may want to peruse the IntelliSense list of objects and properties for each of these data objects... they're pretty powerful... plus, they only open the database when you call for them, so you don't have to worry about closing things up! As for the query that runs when you open the database: what kind of query is it? I'm guessing it's a Make-Table. If so, you could load it into a DataTable object (as I showed above) and access the data from there. All these objects flying around look kinda scary at first... but trust me... if you work with them a while, you'll grow to love them so much more than the old ADO recordsets! If you have any questions, I'll be here for about 4 more hours.
Good Luck!
Ben