carry current value of a control to new records

J

jn

how can you carry forward the current value of a control
so that is is automatically entered for new records?

tried this code that found on
mvps.org/access/forms/frm0012.htm

const.cquote = """"
me!control.defaultvalue = cquote & me!control.value &
cquote

this code is attached to a command button so can
conditionally run it.

code does not work.

want to populate the new record and there are changes want
to be able to key over the info.


the example is one of an insurance company is assigned to
a patient's visit. when the patient returns, the insurance
company is the same and therefore want that info from the
previous visit to populate the new visit.
 
J

John Vinson

const.cquote = """"
me!control.defaultvalue = cquote & me!control.value &
cquote

Should be

Me!control.Default

and of course you need to change "control" to the actual name of the
control on your form.
 
J

jn

john,
changed to default and still did not work.
get an error can not find control name.
the name is spelled correctly.
i am trying to bring forward street, city, state from a
previous record. let us say that the textbox field name is
insurance street. i click on the after update property for
this field. then i put the suggested code in that vb
section.
when i go to a new record, i do not see any info in street.
when i key information, i immediately get the error 'can
not find control name'.

the orig code was from mvps.org/access/forms/frm0012.htm
and also from a response made by marshall barton on 9/30
on the security section of this website.
 
M

Michel Walsh

Hi,


The default value enters in play at the precise moment the new record is
to be created. When you see the record, it is already "created", changing
the default values won't do any thing to IT. The modifications your code
brought will only enter in play for the NEXT record to be created, and will
put whatever is actually present in the control, probably a NULL, as the
default value for the next new record. That is why the code you mentioned is
generally better placed in the AfterUpdate event of the FORM, since at that
moment, the actual record had been saved ( and validated ), hold a valid
value and "something" is likely to occur next, such as the creation of a
new record. You just have a bad timing and probably the incorrect
representation of what a default value is, in term of a control. In human
speech, a "default value" may mean "if nothing is specified, use that". In
that expression, this is more in the spirit of "standard" option, what come
with something when no specific instructions are supplied, than with "by
default" concept, which mean propose something, tentatively, and the user
may write over it.



Hoping it may help,
Vanderghast, Access MVP
 
J

jn

tried your suggestion of doing the after update at the
form level. still did not work. kept getting messages that
could not find the control field.

the control name is identified as
secn_insurance_street_field and the control source is
secn_insurance_street. tried both names in the me!default
routine and got the error mentioned.

so then built a very small test file with 2 fields. the
fields were identified as street and city. only put the
me on the street field. then got the message 'object does
not support this property or method'.

so not sure why keep having problems, in that using the
code specified and using at the after update level.

thanks
 
M

Michel Walsh

Hi,



Open Northwind,

open the form Suppliers in design mode,

add the code:
=======================
Private Sub Form_AfterUpdate()
Me.CompanyName.DefaultValue = """" & Me.CompanyName & """"
Me.ContactName.DefaultValue = """" & Me.ContactName & """"
End Sub
=======================

Switch in normal view, append a record through the >* button (at the
bottom), type toto in company name, and toto Qwerty in the contact name.
Fill other fields (to make the test more illustrative). Click on the >* to
save and to add another supplier, observe that toto and Toto Qwerty are
proposed as value for that new record.

Does that work for you in Northwind?


Vanderghast, Access MVP
 
J

jn

that works, but it will not go to the next blank screen
unless i hit the >* at the bottom.

i tried my simple file again. i find that if i use the
name of the text box and not the control source,that it
will bring info forward. even though i used underscores
to represent spaces in the name, it seemed that you had to
get rid of spaces before it would acknowledge that the
field existed.

so, i applied this logic to the original form and still
have problems.

i have a situation where i have patient visits in a sub
form and the main account info in the main form. the
visits are sorted such that the most current is first.

what i am finding that even though the info came forward
in my simple example, it still does not want to work in
main program.
 

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