Copy field in one entry to an new entry

R

Roy Carlson

I have a form which has only 2 fields. I have also added a "add new record"
button to the form. When I click the button, I would like the information in
one of the fields to automatically show up in the same field of the new
record. What is the easiest way?

Thanks
 
J

John W. Vinson

I have a form which has only 2 fields. I have also added a "add new record"
button to the form. When I click the button, I would like the information in
one of the fields to automatically show up in the same field of the new
record. What is the easiest way?

Thanks

One way is to use a bit of VBA code in the control's AfterUpdate event:

Private Sub controlname_AfterUpdate()
Me!controlname.DefaultValue = """" & Me!controlname & """"
End Sub

If you enter 123 in the control, this will set that control's default value
property to "123"; a new record will then populate with that value, but still
allow the user to overtype it.

John W. Vinson [MVP]
 
J

Jeanette Cunningham

Hi Roy,
you can set the default value property of that field.

Here is an example for a textbox called txtA

Private Sub txtA_AfterUpdate()
Me.txtA.DefaultValue = " & Me.txtA & "
'Me.txtA.DefaultValue = """ & Me.txtA & """
End Sub

If txtA is a text data type, use 'Me.txtA.DefaultValue = """" & Me.txtA &
""""
and comment out the line above it.
When the form opens, you will type in the value for txtA, when you go to the
new record the value for txtA will be there.
When you close the form and reopen it, the value for txtA will need to be
entered manually for the first record.

Jeanette Cunningham
 
L

Linq Adams via AccessMonster.com

Me.txtA.DefaultValue = " & Me.txtA & "

does not work for a numeric field, it'll give you a #Name? in the textbox! It
has to be

Me.txtA.DefaultValue = Me.txtA

Here are examples for Text, Numeric and Date datatype fields

For Text fields

Private Sub YourTextControlName_AfterUpdate()
If Not IsNull(Me.YourTextControlName.Value) Then
YourTextControlName.DefaultValue = """" & Me.YourTextControlName.Value &
""""
End If
End Sub

For Numeric fields

Private Sub YourNumericControlName_AfterUpdate()
If Not IsNull(Me.YourNumericControlName.Value) Then
YourNumericControlName.DefaultValue = Me.YourNumericControlName.Value
End If
End Sub

For Date fields

Private Sub YourDateControlName_AfterUpdate()
If Not IsNull(Me.YourDateControlName.Value) Then
YourDateControlName.DefaultValue ="#" & Me.YourDateControlName & "#"
End If
End Sub
 
S

Steve Schapel

Roy,

You have been given some good advice here, on the assumption that your
form is a Single Form view. It will not work like this if you are using
a Continuous form.
 
L

Linq Adams via AccessMonster.com

How can somebody who signs MVP after his name make such a BS comment? The
valid code given here, both mine and others, most certainly will work on a
Continuous form!
 
S

Steve Schapel

Linq,

MVP doesn't mean infallible. Thank you for pointing out my mistake. On
reflection, I realise I was getting confused with other Default Value
functionality that does differ between single and continuous form behaviour.
 
R

Roy Carlson

Ok, it makes sense to me, so when I get back to work on Monday I'll try these
approaches. I'm just trying to make life easy for some of the students who
take my place when I graduate in the spring. Taking an office from piles of
paper to paperless takes a lot of good ideas, and these ideas should finish
this particular project...now on to the next.
 
Top