Peter Zeman
Sep 23rd, 1999, 07:32 AM
I am writing an application that uses VB6 as a front end and Access 97 as a back end. I have come across one problem. I have been unable to add a new record to a table in the database from VB. I have tried using all kinds of recordsets, including table-type and have been unsuccessful.
I have been successful with the Edit/Update methods with existing records that were added through Access.
It seems that the AddNew method does create an empty record with null values at the end of the recordset and that the data is being correctly assigned to the recordset from the textboxes. However the data fails to show up in the Access table. The table has an autonumber primary key and that number is incremented every time I try to add a record to the table. I am at a loss as to where the problem is and therefore, how to solve it.
Is the problem in the VB code or is it in the Access database. If anyone can help it would be appreciated. I have included the basics of my latest code for this procedure.
Set db = DBEngine.Workspaces(0).OpenDatabase(DBPath)
Set QuDef = db.QueryDefs("QueryName")
Set rs = QuDef.OpenRecordset()
rs.AddNew
rs![FirstField] = form.textbox(1).text
.
.
.
rs![LastField] = form.textbox(n).text
rs.Update
rs.Bookmark = rs.LastModified
Thanks in advance,
Peter
I have been successful with the Edit/Update methods with existing records that were added through Access.
It seems that the AddNew method does create an empty record with null values at the end of the recordset and that the data is being correctly assigned to the recordset from the textboxes. However the data fails to show up in the Access table. The table has an autonumber primary key and that number is incremented every time I try to add a record to the table. I am at a loss as to where the problem is and therefore, how to solve it.
Is the problem in the VB code or is it in the Access database. If anyone can help it would be appreciated. I have included the basics of my latest code for this procedure.
Set db = DBEngine.Workspaces(0).OpenDatabase(DBPath)
Set QuDef = db.QueryDefs("QueryName")
Set rs = QuDef.OpenRecordset()
rs.AddNew
rs![FirstField] = form.textbox(1).text
.
.
.
rs![LastField] = form.textbox(n).text
rs.Update
rs.Bookmark = rs.LastModified
Thanks in advance,
Peter