
ADO + Access97: please help with AddNew-Method
hi,
Im using VB 6, ADO and Access97. In the VB-Frontend a form is
supported by a data aware class and i can read data, navigate, edit
and delete records. But Ive got difficulties in adding new records.
To add a new record, all controls are set to unbound mode in advance.
To save the record, a routine sends the data to a add-new-function in
the data class. If there is no record in the table, the first record I
insert in the form will be written to the database at once. All
following new records are only written to the buffer of the
ado-recordset of the data aware class. They are displayed in the form
so i can navigate forwards and backwards, but they are not saved to
disk. If I close the form or the application the 2nd and following
records are lost.
Ive tried all combinations of update-, updatebatch- and
requery-method with no luck.
Also I tried the AddNew-method with the fields- and values-argument.
Extracts from code:
Connection:
Set DBSys = New ADODB.Connection
DBSys.Provider = "Microsoft.Jet.OLEDB.3.51"
DBSys.CursorLocation = adUseClient
DBSys.Open "C:\.....mdb"
`Declare recordset in data aware class:
Private WithEvents RS_Main As ADODB.Recordset
Private Sub Class_Initialize()
Set RS_Main = New ADODB.Recordset
sSQL = "SELECT * FROM std_Clients_S04"
RS_Main.Open Source:=sSQL, ActiveConnection:=DBMain,
CursorType:=adOpenDynamic, LockType:=adLockOptimistic
...
Add new record:
Public Sub AddNew(ByVal sFieldArray)
Dim iCnt1 As Integer
RS_Main.AddNew
For iCnt1 = LBound(sFieldArray, 2) To UBound(sFieldArray, 2)
If sFieldArray(0, iCnt1) <> "" And sFieldArray(1, iCnt1) <> ""
Then
RS_Main(sFieldArray(0, iCnt1)) = sFieldArray(1, iCnt1)
End If
Next iCnt1
RS_Main.Update
RS_Main.UpdateBatch
End Sub
Is there something missing?
Any hints will be greatly appreciated
oliver