Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Beginner
Mar 3, 1997

Adding a new record in a VB 4.0 database

Question:
When I use my add record button on my form I get blank fields, like I should. However, after I add the new info and move to a different record I find that my new record has overwritten an existing record. I am trying to use the AddNew and Update methods without success. Any advice? Here is the code in the click event of my add button. The info must change on 3 forms.
 Equip.SetFocus
      Data1.Recordset.AddNew
      Thermal.Data1.Recordset.AddNew
      Contam.Data1.Recordset.AddNew
      Data1.Recordset.Update
      Thermal.Data1.Recordset.Update
      Contam.Data1.Recordset.Update

Answer:
First of all, you have to call the AddNew function before you add your data through the bound controls on your form. Most of the forms I saw in the examples provided by Microsoft had an Add and Update button. To add a record, you press the Add button, and to save it, you press the Update button. The Add button had the AddNew code in it, and the Update button had the Update code in it. Once you have made that change, you may also have to change the way you are referencing the Data controls on the other forms. For instance, Therma1.Data1.Recordset.Update may need to become Therma1!Data1.Recordset.Update. Try it the way you have it first and if it doesn't give you an error, it's probably ok.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

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