Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Database and Reporting > VB and data control


Reply
 
Thread Tools Display Modes
  #1  
Old 09-06-2002, 04:33 AM
Hilton Hilton is offline
Freshman
 
Join Date: Sep 2002
Location: London
Posts: 38
Default VB and data control


Making a small application to send possibly large numbers of emails to a user group. It has two forms


On the first form (Hubform) users use checkboxes to define records to be selected from an Access database. Command1 opens Contacts.mdb (ie CreateObject) and runs a query to delete table Contacts, the runs some SQL code which remakes the table (from table Contacts Data) containing the selected records. The database is closed and the form is hidden and the second form is shown.

The second form (Mailform) is used to compose an email message to be sent to the selected records. This form uses a data control and DBgrid to connect to the database.

Before the message is composed or sent, users can reveiw the records made on the previous form. Command button4 conatins the code to connect data1 and DBgrid1 to Contacts.mdb. Users can quite easily de-select records they don't wish to mail to. But the big problem is...

If the selection is wrong in some regard (eg user selected all records with USA in Country field instead of UK), then they need to be able to go back to Hubform and re-submit the query.

Command6 contains the following code, which i think is the problem.


KeyPreview = True
file = App.Path + "\contacts.mdb"
cr = Chr$(13) + Chr$(10)
Dim db As Database
Set db = OpenDatabase(file)
Set rs = db.OpenRecordset("select * from contacts")
Set Data1.Recordset = rs

rs.Close
db.Close

Text1.Text = ""
msg.Text = ""
Mailform.Hide
hubform.Show

It is supposed to close data1 (which i assumed would release the table fo use), clear the contents of the email subject and message the return the user to Hubform.

But when the query is resubmitted, the new selection is ADDED to the table. It seems as if the table is not released by Data1.

CAn anyone help?
Reply With Quote
  #2  
Old 09-06-2002, 07:39 AM
iowahawk43's Avatar
iowahawk43 iowahawk43 is offline
Contributor
 
Join Date: Aug 2002
Location: Iowa
Posts: 450
Default

I assume you are binding your Grid to Data1 data control. This is why you get a recordset and then move that recordset to Data1.Recordset.

It seems a little odd you would create a Recordset object, fill it with records and then move it to the Data Control (other than the convenience of binding to the data grid).

Anyway, so you kill the Recordset object. And the Database object. Cool. What makes you think the Data1 is closed yet? Once you passed the records (Set Data1.Recordset = rs) the link between "rs" and "Data1.recordset" is over.

If you requeried using "rs" object your Data control would not automatically be updated too.

Try getting your new rs filled and then update your Data1 with the new results. Data1.Refresh might be helpful.

By best suggestion...1) start using ADO and 2) avoid the data control (more code, but more control).

Hope this helps.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->