Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi VB experts - I posted in the 1

Status
Not open for further replies.

JohnBates

MIS
Feb 27, 2000
1,995
US
Hi VB experts -

I posted in the VB 5/6 forum but no one responded, so I'll
ask the pros...

Using VB 6, I have a form which allows add/update/delete, with text boxes as data-bound controls via the ADO data control.

The Update and Delete methods work fine.
The problem is with Adding a new record :

*********************************************************
'The following code results in the new record getting written OVER the existing rec that was displayed before entering add mode. Also inserts an EMPTY row!

********************************************************

I am using Textboxes that are automatically bound to the
Recordset fields.

-There is an existing record displayed in the 2 Textboxes
-When the AddRecord button is clicked, I clear the Textboxes
txtCode.Text = ""
txtDesc.Text = ""

-User enters info into the Textboxes
-User clicks another button which does the following...

datPrimaryRS.Recordset.AddNew
datPrimaryRS.Recordset!ReaCode = txtCode.Text
datPrimaryRS.Recordset!ReaDesc = txtDesc.Text
datPrimaryRS.Recordset.Update


The above code causes the previous "current" record to be
destroyed by overlaying it with the newly entered info.

Isn't there a way I can use the data-bound controls, yet not lose a record when an Add is performed ?

Thanks for any help. John
 
I don't often use the ADOC Data control, so this may be a bit off. In general, when ever you manipulate the information in a bound control, the changes are passed through to the record. From this, I assume that when you set the textboxes to blank (e.g. Text1.text = ""), the change is passed to the record and the field bound tot he control is set to blank (zero length string). When the .AddNew is issued, the Recordset pointer is set to the "tenative" append record and The text box contents are (via your code) entered into the record . The .Update causes the record to be 'finalized'.

MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Michael - Thanks for replying.
I don't like the bound controls either, but I'm in pretty deep on this one I guess too, I'm a little bit stubborn.

What you described is just what I assumed would happen.

What is confusing is that it "destroys" the prior record....

The record that ultimately gets lost is the 1 that is showing in the textboxes when I clear them for new input.

Soooo, do I need to position to EOF before I clear the textboxes ?

datPrimaryRS.Recordset.CursorLocation doesnt seem to do what I need.

datPrimaryRS.Recordset.EOF=True ??

Thanks for any ideas. John


 
I don't use bound controls either, but I'm afraid that is not a good enough reason to help!

Why are you doing
datPrimaryRS.Recordset!ReaCode = txtCode.Text
If it is a bound text box, then won't it do this for you?

So if you clear the text boxes and then do an addnew, won't it clear the current record before adding a new one. I would have thought that addnew would clear the textboxes all by itself?
Peter Meachem
peter@accuflight.com
 
As Peter says, issuing the ".AddNew" positions the Record pointer on the "Tenative append" (e.g. "NEW") record - but that is in DAO. ADO workd somewhat differently, and I'm not far enough into using it to be sure of the answer w/o checking - whih I don't have tome to do at the moment. In ADO, you do not use one of the methods (.AddNew or .Update) but WHICH one has escaped my feeblness for the moment.

I do not know how you are sure which record is being "destroyed" from the post. If there are additional fields, perhaps they indicate this, but the post 'implies' the record consist of the two fields bound to the text boxes - once these are cleared, I don't see how you identify the old from the new.

MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
"So if you clear the text boxes and then do an addnew, won't it clear the current record before adding a new one. I would have thought that addnew would clear the textboxes all by itself."

You are correct Peter. Thanks for putting me on the right path!

This is what I ended up with:

datPrimaryRS.Recordset.AddNew 'This clears the textboxes

-User enters info into the Textboxes
-User clicks a Confirm button which does the following...

datPrimaryRS.Recordset!ReaCode = txtCode.Text
datPrimaryRS.Recordset!ReaDesc = txtDesc.Text
datPrimaryRS.Recordset.Update
************************************************
I was clearing the textboxes myself which was destroying the 'current' record.

BTW, just some friendly advice for others who may be tempted to use data-bound controls. This is a powerful feature of VB.... but I will only use data-bound controls for 'display-only' programs in the future. If the program allows updates/adds, it can be difficult to know where to put your input-validation code. Just my opinion.

Thanks for the assist guys. John


 
This should solve your problem. Change the EOFAction property to 2-adDOAddNew in the design-mode.

By the way I highly recommend use ADO the data control is very restrictive.

reidfl "Keep Your Code Tight"
 
Yep. The Data Controls aren't really that good. Learn ADO.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top