Click to See Complete Forum and Search --> : AddNew Overwrites
Rob Brown
May 24th, 2000, 05:51 PM
Hi,
I'm using a DAO data control to connect from VB5 to Access 97 using a dynaset type recordset.
On using the AddNew method the new record is being added over the top of the current record.
This results in the old record being lost when the new record is saved and therefore, no matter how many entries I add, I have only one record in my database.
What am I doing wrong?
Any help would be much appreciated.
Best Regards,
Rob Brown.
GRAHAM
May 25th, 2000, 08:19 AM
Hi Rob,
It sounds as though you've got a statement somewhere that's moving you to the previous record or something.
When you have .AddNew a NEW record is prepared ready for entries, and .Update stores them.
It's always a good idea to post your code with the question...its easier to answer then. Post it and someone will help you (probably not me 'cos its 2.15 a.m and I'm ready for some kip).
Cheers
GRAHAM ;)
Rob Brown
May 25th, 2000, 03:00 PM
Here is my code:
Private Sub mnuReportAddNew_Click()
dtaReport.Recordset.AddNew
End Sub
As you can see it's not very complicated.
According to the help file, with the dynaset type recordset this should add a new record at the end of the recordset amd allow them to edit the new record.
I am then using a save changes menu item to update the database, it uses the following code:
dtaReport.Recordset.Edit
dtaReport.Recordset.Update
Thanks for taking the time to help me out.
GRAHAM
May 26th, 2000, 03:44 AM
Hi Rob,
Take a look at the code in this Function...It illustrates the .AddNew.
Assuming that sName & sPhone are the entered values that were input from textboxes or whatever/whereever
Function AddToDatabase(sName As String, sPhone As String)
'***look at this section******
'Open the Contact table
Set RS = DB.OpenRecordset("SELECT * FROM Contact", dbOpenDynaset)
With RS
'Set it to Add mode
.AddNew
'Enter the field values
.Fields("Name").Value = sName
.Fields("Phone").Value = sPhone
'Update it i.e save
.Update
'Close it
.Close
End With
************************
End Function
The above is very basic, but should point you in the right direction.
I hope this helps you solve your problem; sorry I can't help you any further, but I've got to finish my front-end project(like yesterday)
Cheers
GRAHAM ;)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.