Move data between Subform and Form

rgreene

Registered User.
Local time
Today, 07:03
Joined
Jan 22, 2002
Messages
168
I have a form with a subform and the subform lists a 5 digit code. I want to be able to click on the 5 digit code in the subform and have that number moved/copied to a field on my main form.

Any suggestions?

P.S. I'm new to Access so detailed explanations would be greatly appreciated.

Thanks in advance,

Rick
 
Rick,

Something like this might work...

Private Sub yourField_Click()

Forms!yourMainForm!YourTextboxOnMainForm.SetFocus
Forms!test1!YourTextboxOnMainForm.Text = yourField.Text

End Sub

so the code goes in the click event of the field in your SUBFORM. When you click on the field focus is set to the textbox where you would like the code to be moved to. The last line sets the main form's textbox to equal the code in the subform.

Try it and let me know if that's what you wanted.

Rich
 
This is what I put (I put it in the Double Click instead of Click)

Private Sub PACCode5_DblClick(Cancel As Integer)

Forms!Unassigned Cost Codes Form!PAC5Code.SetFocus
Forms!test1!PAC5Code.Text = PACCode5.Text

End Sub

I get Compile Error

Syntax error
and the first line (Forms!.......) has red text.

Where did I goof?
 
Me.Parent.PAC5Code = Me.PAC5Code

However!!! The recordsource of the mainform and the recordsource of the subform have a one-to-many relationship. What sense does it make to store ONE of the MANY values in the ONE-side table? In addition to making no sense, it is poor practice since it violates second normal form.

The compile error is caused because you used embedded spaces in your form name. A definite no-no. Even though Access allows it, you have to tread lightly if ever you want to reference the object in VBA. Any object name that does not conform to VBA standards MUST be surrounded by square brackets.

Forms![Unassigned Cost Codes Form]!PAC5Code.SetFocus
 
Last edited:
Pat that worked GREAT!!! THANKS!!!

Your However paragraph was that geared to me or the first response post? As I said in my original post I'm just trying to learn some of this stuff. There is probably o alot of things I've done that don't make sense.
 

Users who are viewing this thread

Back
Top Bottom