Problem adding records via Datasheet

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.)
 
M

Mark Jackson

I solved this by creating a hidden table into which data is selected,
base the subform on that hidden table, and then selecting out the data
when the form closes and erasing the table.
 
M

Mark Jackson

I solved this by creating a hidden table into which data is selected,
base the subform on that hidden table, and then selecting out the data
when the form closes and erasing the table.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top