A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Copy field in one entry to an new entry



 
 
Thread Tools Display Modes
  #1  
Old January 4th, 2008, 11:08 PM posted to microsoft.public.access.forms
Roy Carlson
external usenet poster
 
Posts: 12
Default Copy field in one entry to an new entry

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
  #2  
Old January 4th, 2008, 11:24 PM posted to microsoft.public.access.forms
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Copy field in one entry to an new entry

On Fri, 4 Jan 2008 15:08:00 -0800, Roy Carlson
wrote:

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]
  #3  
Old January 4th, 2008, 11:32 PM posted to microsoft.public.access.forms
Jeanette Cunningham
external usenet poster
 
Posts: 2,190
Default Copy field in one entry to an new entry

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




"Roy Carlson" wrote in message
...
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



  #4  
Old January 5th, 2008, 12:12 AM posted to microsoft.public.access.forms
Linq Adams via AccessMonster.com
external usenet poster
 
Posts: 1,474
Default Copy field in one entry to an new entry

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

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200801/1

  #5  
Old January 5th, 2008, 08:05 AM posted to microsoft.public.access.forms
Steve Schapel
external usenet poster
 
Posts: 1,422
Default Copy field in one entry to an new entry

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.

--
Steve Schapel, Microsoft Access MVP

Roy Carlson wrote:
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

  #6  
Old January 5th, 2008, 11:22 AM posted to microsoft.public.access.forms
Linq Adams via AccessMonster.com
external usenet poster
 
Posts: 1,474
Default Copy field in one entry to an new entry

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!

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...forms/200801/1

  #7  
Old January 5th, 2008, 06:47 PM posted to microsoft.public.access.forms
Steve Schapel
external usenet poster
 
Posts: 1,422
Default Copy field in one entry to an new entry

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.

--
Steve Schapel, Microsoft Access MVP

Linq Adams via AccessMonster.com wrote:
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!

  #8  
Old January 6th, 2008, 08:54 PM posted to microsoft.public.access.forms
Roy Carlson
external usenet poster
 
Posts: 12
Default Copy field in one entry to an new entry

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.

"John W. Vinson" wrote:

On Fri, 4 Jan 2008 15:08:00 -0800, Roy Carlson
wrote:

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]

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:40 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.