Copying variable fron 1 form to another.

gpurger

Registered User.
Local time
Today, 00:54
Joined
Apr 21, 2004
Messages
66
passing and liknking data between 2 forms

I have two basic forms, each with a sub and a subsub form.
The first is for the main assembly type with a sub form for the serial numbers and a subsub form to track its history, (FrmMainItem)
The second form has the same structure but is for any sub assemblies, (FrmSubItem)
I can link both forms so that when a button is pressed on FrmMainItem FrmSubItem opens with the relevant sub assemblies.
I have a table for each form and sub form(6 in total):

Main item details
Main Item Serial Number (can be more than one)
Main Item Movement details. (need to capture movement history of the specific item).
These are repeated for the Sub Assemblies
My problem is when I want to create a new set of data using FrmSubForm.
How can I place the FrmMainItem [PartNum] value into the FrmSubItem[PartNum] field automatically. :confused:
 
Have the PartNum be in the Master & Child Link properties for the subform.
 
Thanks for your reply but it does not help because I can not see where to add the parent / child links. They are not visiable on the properties list.

Remember that I am opening a new form from the original.
I tried the wizard but this only works if there are matching pieces of data in both tables.
I think I need some vb to help

Cheers


Gordon
 
I'd try setting the DefaultValue property of a control on the form in question.
Set it's value in the Form_Current() event handler.
You can refer to the parent of the subform using 'Me.Parent' and get at its controls.

Private Sub Form_Current()
~~Me.SomeSubformControl.DefaultValue = Me.Parent.SomeIDControl
End Sub

Also, from a SubSubSubSubform, which is probably impossible, you can reference the main form as follows

Private Sub Form_Current()
~~Me.SomeSSSSSubformControl.DefaultValue = Forms!YourMainForm.SomeID
End Sub
 
Thanks for that but regretfully I get the ' invalid reference to the Parent property' error message (error 2452)

This is what I have coded

Private Sub Form_Current()
Dim newval As String

newval = Me.Parent.PartNum

If IsNull(Me.PartNum) Then
Me.PartNum.DefaultValue = newval

End If

End Sub

Cheers

Gordon
 
Hi,

I posted this question on the forms area but with no luck, hope it is OK to try here.
I need to copy the value of a field from 1 form to another form I open using a button. I can not use subforms.
Cheers

Gordon
 
Gordon:

If the button is on FormA (and FormB is open):

Forms![FormB]![SomeField] = Me.SomeField

Wayne
 
Gordon

Assuming both forms are open this should be straight foward. A line from a recent project illustrates this

Forms!frmcreateinvoice!sfrmInvoiceDetail.Form!txtEngineerCode = strEngineerCode

there is no reason why the string could not be replaced by a reference to to a field on a form.

just create a button and put the code in the on click event
 
and if one of the forms is closed, you're going to want to base the form field on a table's field.

then just reference the table, but the above should be what you're looking for.
 
Thanks for that, it got rid of the errors when I used the posted code.

stDocName = "SfrmSubItem"
DoCmd.OpenForm stDocName
DoCmd.GoToRecord , , acNewRec
Forms![SfrmSubItem]![MainPartLink] = Me.PartNum.

Do I have to refresh aswell? It does not save to the table.

Thanks for your time

Gordon
 
Is Forms![SfrmSubItem]![MainPartLink] linked with a table field?

Also:

Forms![SfrmSubItem]![MainPartLink].Value = Me.PartNum.Value

would be better practice
 
Is Forms![SfrmSubItem]![MainPartLink] linked with a table field?
One to Many link from main table.

Thanks for your help
 
Sorry I haven't given you much time, but is there a reason why you don't go to your SfrmSubItem form code and say:

Me.MainPartLink.Value = Forms![OtherFormYou'reComingFrom]![PartNum].[Value] ?
 

Users who are viewing this thread

Back
Top Bottom