Moving data from Public variable to Table field on Add?

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

Guest

I have a form that allows me to add data to a table. I have a Public variable
that holds a certain value from another form. When I click the Add button (
* ), i need that variable's value to be posted to the record being added.
How can I do that please? I've been working on this for hours.

Thanks!
 
Dennis said:
I have a form that allows me to add data to a table. I have a Public variable
that holds a certain value from another form. When I click the Add button (
How can I do that please? I've been working on this for hours.


Not 100% sure what you want here, but I think this might be
close.

Place something like the following in the form's Current
event procedure.

If Me.NewRecord Then
Me.sometextbox.DefaultValue = """" & publicvariable & """"
End If

All those quotes are unnecessary if the field bound to the
text box in a numeric type.
 
Thanks. I can get the var onto the form okay during OnOpen. What I need to do
is make sure the *value* I have in that Unbound field is placed into the NEW
record with the other data.

Thanks!
 
What unbound "field" are you talking about?

I had assumed that the sometextbox control was **bound** to
the table field that should receive the value in
publicvariable. I used the bound text box's DefaultValue
property so the new record would not be dirtied by the code,
but if the user actually enters some data in another
control, then the value would be automatically filled in.
 
If I bind the control, can I still set the Me.MyField.Value = memoryVarValue ?

Marshall Barton said:
What unbound "field" are you talking about?

I had assumed that the sometextbox control was **bound** to
the table field that should receive the value in
publicvariable. I used the bound text box's DefaultValue
property so the new record would not be dirtied by the code,
but if the user actually enters some data in another
control, then the value would be automatically filled in.
--
Marsh
MVP [MS Access]


Thanks. I can get the var onto the form okay during OnOpen. What I need to do
is make sure the *value* I have in that Unbound field is placed into the NEW
record with the other data.
 
As long as the text box does not have a control source
**expression**, then, Yes you can do that. But as I said
before, using the Value property in the Load event (not the
Open event) will dirty the record and make it difficult for
the user to change their mind about wanting a new record.
 
Thank you. I'll try that. However, if you know of a different way to get that
one value added to the record after it's added (via update in some *simple*
way, I'd love to hear about it. I already know the methodolgy where you frine
a recset, open it, update it and close it. But I felt that since the rec was
being freshly added, that there'd be a simple way of doing it. I don't need
that field on the form, as it's already "public". All I need to do is add
that value to the new record once added.

Any ideas?

Marshall Barton said:
As long as the text box does not have a control source
**expression**, then, Yes you can do that. But as I said
before, using the Value property in the Load event (not the
Open event) will dirty the record and make it difficult for
the user to change their mind about wanting a new record.
--
Marsh
MVP [MS Access]

If I bind the control, can I still set the Me.MyField.Value = memoryVarValue ?
 
I think what I posted is maybe a little more than you need
if there is no need to display the value. In the case
you're describing, I suggest using the form's BeforeInsert
event to just copy the value to the field (must be in the
form's record source):

Me!fieldname = publicvariable

Note that I use the words "control" and "field" rigorously.
A field is a column in a table/query. Controls are used on
a form/report to display formatted values.
 
Back
Top