I have a form (called "MainForm") whose
"DataEntry" property is set to "true" and
whose "RecordSource" property is set to
table "MainTable", which itself contains
two string fields naned "main1" and
"main2", as well as six other string fields
named "item1" through to "item6"
"MainForm" contains a text box
control named "txtMain" whose
"controlSource" property is
set to "mainfld", as well as a sub-form
named "subf", whose "DataEntry"
property is also set to "true", which
is set to "Continuous Forms" display mode,
whose "RecordSource" is set to another
table named "SubTable", (which has a
string field named "subfld"), and
which has a "text box" control named
"txtSub" whose "ControlSource" property
is set to "subfld"
I want to set up a eituation in which
"MainForm" (being in "DataEntry" mode)
creates a "MainTable" row by the
entry of data into "txtMain" as well
as the creation of a row of "SubTable"
for each entry of data into "txtSub" (Since
that form is also in "DataEntry"
mode) ...
All quite traight-forward so far,
I hear you thinking, all handled
quite easily by the Access GUI: the
extra twist, however, is that, for
the first 6 rows created in
"SubTable" (by the entry of data
into the corresponding "txtSub" text
box), I also want the contents of
rach "txtSub" text-box to be
copied to the "item<n>" fields (of
"MainForm")
Here's the VB code I creaated in
my attempt to sccomplish this task:
> sub add_items()
>
> Dim i as Integer = 1
> Dim rmain As DAO.Recordset = _
> CurrentDB.OpenRecordset("MainTable")
>
> ' rget recordset behind sub-form of "MainForm"
> Dim rsub As DAO.Recordset = _
> Forms!MainForm!subf.Form.RecordsetClone
>
> rsub.MoveFirst
>
> ' cycle through each record in sub-form
> while i < 6 and not rsub.EOF
>
> rmain.Edit 'preare for changes to "rmain"
>
> ' set "MainTable"'s "item<n>" field
> ' from current sub-form text box
> rmain("item" & i) = rsub("subfld")
> rmain.Update ' commit changes
>
> i = i + 1
> rsub.MoveNext
>
> wend
>
> end sub
My thinking in the design of the
above code was that, since a row
of "MainForm" will have already
been craated by entry of data
into "txtMain"(since "MainForm" is
in "DataEntry" mode), then the VB
code merely needs to "Edit" the
row to set the "item<n>" fields of
that created row ...
Trouble is, after this code is run
I find that, while a erow of
"MainTable" is created as
expected, and the contents of the
"mainfld" field was set
correctly from the "txtMain" text
box, I found all of the "item<n>"
fields were set instead to "null"
Does anyone know what I'm doing
wrong and how I might be able to
fix this code?
Thanks,
Russell
>> Stay informed about: Problem with ""Recordset.Edit"" on a ""DataEntry"" form in Ace..