Copy and paste value from one field to another

andyg75

New member
Local time
Today, 14:23
Joined
Sep 29, 2005
Messages
5
Here's what I would like my macro to do:

1. Select and copy the text in a particular field in the active form
2. Open another form
3. Create a new record
4. Paste the copied text into a field in the new form

Everything except step one seems to be fairly easy/straightforward. However, I cannot figure out how to select the contents of a particular field in the active form. There's no "goto field" command.

Any suggestions? Thanks.

:confused:
 
Hi,
instead of using a macro try to adapt VBA (visual basic for applications) code.
Macros are very limited and you will need to learn VBA at some point anyway.
So you could do something like this on the on click event of a button:

DoCmd.OpenForm "YOURFORMNAME", acNormal
DoCmd.GoToRecord , , acNewRec
Forms!YourFormName.ControlName.Value = Me.YourControl

You could probably also use openargs to pass the value if you wanted.
HTH
Good luck
 
freakazeud said:
Hi,
instead of using a macro try to adapt VBA (visual basic for applications) code.
Macros are very limited and you will need to learn VBA at some point anyway.
So you could do something like this on the on click event of a button:

DoCmd.OpenForm "YOURFORMNAME", acNormal
DoCmd.GoToRecord , , acNewRec
Forms!YourFormName.ControlName.Value = Me.YourControl

You could probably also use openargs to pass the value if you wanted.
HTH
Good luck
Thanks immensely for your help and advice. I know VBA is the way to go in the long run but I'm like one step of getting this working and i just wanted to have it done so I could show the folks in my department how it's going to work...

That all makes sense except for line 3. I'm not sure which parts of that get entered verbatim and which parts are supposed to be subsititued with specific values from my database. I don't see where I'm specifying that I would like to select the value of a field in the current form and set the value of a field in the newly opened form to be the same.
 
Check this part:

Forms!YourFormName.ControlName.Value = Me.YourControl

(New form control value)_____(set equal to)____(Current control value)

You might need to play a little around with the syntax as the current form might be the one just opened and not the one where the button was pressed from. Then you need to switch it around :)!
HTH
Good luck
 
freakazeud said:
Check this part:

Forms!YourFormName.ControlName.Value = Me.YourControl

(New form control value)_____(set equal to)____(Current control value)

You might need to play a little around with the syntax as the current form might be the one just opened and not the one where the button was pressed from. Then you need to switch it around :)!
HTH
Good luck
so the syntax for the left side of the equation is:

Forms!NewFormName.FieldNameToBeSet.Value

and the syntax for the right side is:

Me.OriginalFormName.FieldNameToBeCopiedFrom

I get this error: Compile Error: Method or data member not found. the script debugger comes up and the .OriginalFormName in the 3rd line is highlighted.
 
No you have to figure our which one is the current form.
I assume that the one where the button was clicked from will still be the current form, but I'm not 100% sure as a new form gets opened and if that one receives focus in between execution then that is the current form so it is either:

New form is current form:

Me.YourField.Value = Forms!OldFormName!OldControl.Value

OR old form is current form:

Forms!OldFormName!OldControl.Value = Me.YourField.Value

With openargs this would look something like this on the on click of the button:

DoCmd.OpenForm "Employees", acNormal, , , acReadOnly, _
, Me.YourField

Then on the on open event of the new form it would be:

Sub Form_Open(Cancel As Integer)
Dim strYourValue As String
strYourValue = Forms!YourNewForm.OpenArgs
If Len(strYourValue) > 0 Then
DoCmd.GoToRecord , , acNewRec
Me.YourControl.Value = strYourValue
End If
End Sub

HTH
Good luck
 
that is the sort of complexity i was trying to avoid. is there no way using a macro to select the text in a specific field and copy it to the clipboard?
 
i got over it and used the VB code. here's what ended up working:

Forms!NewForm.FieldToCopyTo.Value = Forms!OldForm.FieldToCopyFrom.Value

thanks much for your help!
 

Users who are viewing this thread

Back
Top Bottom