passing a value into multiple consecutive new records

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i have a form which requests that the user select a value from a combobox,
which gets inserted into a field in a new form. i need for this same value
to get inserted into all subsequent new records.

i can't figure out how to accomplish that. can anyone help?

tia,
janaki
 
Do you want this to happen for all new records until the "new" form is
closed again, or until the user makes a different selection from the
original combobox?

If the former, you can get the "new" form to pick up the value from the
combobox on the first form, with code like this in its Load or Open
event procedure. I'll assume that the forms are frm1 and frm2, the combo
box is called cboSetTheValue, and that the new form has a textbox
txtTheValue bound to the field in question.

'Make sure frm1 is open
Dim j As Long
For j = 0 to Forms.Count - 1
If Forms(j).Name = "frm1" Then
'frm1 is open, get the default value
Me.txtTheValue.DefaultValue = _
Forms(j).Fields("cboSetTheValue").Value
End If
Next

If you want the default value to persist if frm2 is closed and
re-opened, or if the database is closed and re-opened, you need to

(a) put code in cboSetTheValue's AfterUpdate event to store the value
somewhere, e.g. in a "Settings" table in the database or in an .ini
file.

(b) have the code in frm2's Load or Open event handler retrieve the
stored value.
 
thanks for the response - the first option is what i'm looking for, but now,
i'm getting an error (Run-time error '2465': Application-defined or
object-defined error)

and the line that is highlighted is

Me.txtTheValue.DefaultValue = _
Forms(j).Fields("cboSetTheValue").Value

(and yes, i've changed "txtTheValue" to the control name on form #2, and
change "cboSetTheValue" to the control on form#1 that holds the value)

any thoughts on how to debug this??

thanks,
janaki
 
If your controls have different names from the fields they're bound tok,
it's because I wrongly typed
Forms(j).Fields("cboSetTheValue").Value
and you didn't correct it to
Forms(j).Controls("cboSetTheValue").Value
<g>.

Otherwise, set a breakpoint on that line, and when the code stops there
check the values of
Forms(j).Name
Forms(j).Controls("cboSetTheValue").Value
and so on.

Also: is the combo box on Form #1, or on a subform?
 
Back
Top