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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|