M
Mark Jackson
Hi,
I am trying to add records to a disconnected ADODB recordset via a
datasheet. I created a record set, added fields, populated it with
data, and bound the fields in my datasheet to the fields in the
recordset. When I navigate to the empty row at the end of the form and
try to type in a new record, a record is added to the recordset for
every keystroke.
Attached is the code:
Set formRS = New ADODB.Recordset
formRS.CursorLocation = adUseClient
formRS.Fields.Append "myID", adInteger, 8, adFldIsNullable And
adFldUpdatable
formRS.Fields.Append "FuturesSymbol", adChar, 4, adFldUpdatable
formRS.Fields.Append "Legend", adChar, 255, adFldUpdatable
myField = formRS.Fields(0)
formRS.Open , , adOpenDynamic, adLockOptimistic
i = 0
Do Until dbRS.EOF
formRS.AddNew
formRS.Fields("myID").Value = i
formRS.Fields("FuturesSymbol").Value =
dbRS.Fields("FuturesSymbol").Value
formRS.Fields("Legend").Value = dbRS.Fields("Legend").Value
i = i + 1
dbRS.MoveNext
Loop
Set Me.Recordset = formRS
dbRS.Close
Set dbRS = Nothing
Set myIndex = Me!IndexTextBox
Set mySymbol = Me!SymbolTextBox
Set myDesc = Me!DescTextBox
myIndex.ControlSource = "myID"
mySymbol.ControlSource = "FuturesSymbol"
myDesc.ControlSource = "Legend"
(This is just test data, in the real database the information in the
datasheet will be more complicated and drawn from many tables. I also
don't want any changes made in the form to be saved to the database.)
I am trying to add records to a disconnected ADODB recordset via a
datasheet. I created a record set, added fields, populated it with
data, and bound the fields in my datasheet to the fields in the
recordset. When I navigate to the empty row at the end of the form and
try to type in a new record, a record is added to the recordset for
every keystroke.
Attached is the code:
Set formRS = New ADODB.Recordset
formRS.CursorLocation = adUseClient
formRS.Fields.Append "myID", adInteger, 8, adFldIsNullable And
adFldUpdatable
formRS.Fields.Append "FuturesSymbol", adChar, 4, adFldUpdatable
formRS.Fields.Append "Legend", adChar, 255, adFldUpdatable
myField = formRS.Fields(0)
formRS.Open , , adOpenDynamic, adLockOptimistic
i = 0
Do Until dbRS.EOF
formRS.AddNew
formRS.Fields("myID").Value = i
formRS.Fields("FuturesSymbol").Value =
dbRS.Fields("FuturesSymbol").Value
formRS.Fields("Legend").Value = dbRS.Fields("Legend").Value
i = i + 1
dbRS.MoveNext
Loop
Set Me.Recordset = formRS
dbRS.Close
Set dbRS = Nothing
Set myIndex = Me!IndexTextBox
Set mySymbol = Me!SymbolTextBox
Set myDesc = Me!DescTextBox
myIndex.ControlSource = "myID"
mySymbol.ControlSource = "FuturesSymbol"
myDesc.ControlSource = "Legend"
(This is just test data, in the real database the information in the
datasheet will be more complicated and drawn from many tables. I also
don't want any changes made in the form to be saved to the database.)