Solved Open Args to a subform (1 Viewer)

AlexN

Registered User.
Local time
Today, 10:15
Joined
Nov 10, 2014
Messages
302
Hi everyone,

Suppose, closing a form, I want to pass a value to a control in opening form's subform.
This subform control doesn't exist on opening main form.
Is it doable and how?


Thanks
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 04:15
Joined
May 21, 2018
Messages
8,463
Normally you can pass this openargs to the main form and have the subform pull from the main form or have the main form push to the subform. Depends on how you are opening things. Normally forms load from the inside out. Subforms then mainform.
What do you mean the subform control does not exist? Are dynamically creating controls? Not a good idea?
 

AlexN

Registered User.
Local time
Today, 10:15
Joined
Nov 10, 2014
Messages
302
I mean, main form and subform are related through other controls. The control to which I want to pass the open args value doesn't belong to the main form's record source.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 01:15
Joined
Oct 29, 2018
Messages
21,358
I mean, main form and subform are related through other controls. The control to which I want to pass the open args value doesn't belong to the main form's record source.
It shouldn't matter. You can pass any value to the main form's OpenArgs and then use it elsewhere.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 04:15
Joined
May 21, 2018
Messages
8,463
Do you need to pass 2 values? One for filtering the main form and one for the subform? Can you give an example of what you want to pass and then what you want to happen with the subform?
 

AlexN

Registered User.
Local time
Today, 10:15
Joined
Nov 10, 2014
Messages
302
Do you need to pass 2 values? One for filtering the main form and one for the subform? Can you give an example of what you want to pass and then what you want to happen with the subform?
Let's say the main form holds invoice (number, date, recipient etc) and subform holds invoice details (product, value, etc). I want to open the main form passing a value to the product control on the subform. Main and subform are linked through InvoiceID.
 

AlexN

Registered User.
Local time
Today, 10:15
Joined
Nov 10, 2014
Messages
302
Sorry, I'm not following. Are you asking how to pass a value to the OpenArgs property or how to use it after passing it?
I'm asking how to use the Open Args value to populate the subforms control. There's no control in main form that can hold this value.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 01:15
Joined
Oct 29, 2018
Messages
21,358
I'm asking how to use the Open Args value to populate the subforms control. There's no control in main form that can hold this value.
Okay, as I said earlier, the main doesn't need any control for that value, because it's already stored in one of its properties. Which event were you planning to use to assign the value to the subform?

Sent from phone...
 

AlexN

Registered User.
Local time
Today, 10:15
Joined
Nov 10, 2014
Messages
302
OnLoad I suppose (main form's on load)
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 04:15
Joined
May 21, 2018
Messages
8,463
Do you want it to set the value of the Product in the subform for a new product?
 

AlexN

Registered User.
Local time
Today, 10:15
Joined
Nov 10, 2014
Messages
302
Do you want it to set the value of the Product in the subform for a new product?
Nope, for an existing one, since it comes from another form anyway
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 04:15
Joined
May 21, 2018
Messages
8,463
In this example I pass in a ToolID to set the value in the subform. I check if an openargs was passed. In this case I move to a new record and then set the value of the control (toolID_FK)

Code:
Private Sub Form_Load()
  If Not (Me.OpenArgs & "") = "" Then
    With Me.tblAssemblies_Tools_subform.Form
      .Recordset.AddNew
       .toolID_FK = Me.OpenArgs
    End With
  End If
End Sub

If you do not move to a new record or a specific record you are just going to change the value of the first record.
 

AlexN

Registered User.
Local time
Today, 10:15
Joined
Nov 10, 2014
Messages
302
In this example I pass in a ToolID to set the value in the subform. I check if an openargs was passed. In this case I move to a new record and then set the value of the control (toolID_FK)

Code:
Private Sub Form_Load()
  If Not (Me.OpenArgs & "") = "" Then
    With Me.tblAssemblies_Tools_subform.Form
      .Recordset.AddNew
       .toolID_FK = Me.OpenArgs
    End With
  End If
End Sub

If you do not move to a new record or a specific record you are just going to change the value of the first record.
Yeah, I forgot to say that Main form opens on Add mode so no existing record has to change
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 04:15
Joined
May 21, 2018
Messages
8,463
That could be problematic. I have to test. If the Mainform is in addmode, you may not be able to set the value in the subform on load since you cannot create a child record when no parent record. You may have to wait until you create a main form record.
Ok I tested, it worked in my case but could depend on how you have relational integrity set.
 

AlexN

Registered User.
Local time
Today, 10:15
Joined
Nov 10, 2014
Messages
302
That could be problematic. I have to test. If the Mainform is in addmode, you may not be able to set the value in the subform on load since you cannot create a child record when no parent record. You may have to wait until you create a main form record.
Ok I tested, it worked in my case but could depend on how you have relational integrity set.
Yes. tested it already and didn't work apparently because of this...any ideas?
 

AlexN

Registered User.
Local time
Today, 10:15
Joined
Nov 10, 2014
Messages
302
That could be problematic. I have to test. If the Mainform is in addmode, you may not be able to set the value in the subform on load since you cannot create a child record when no parent record. You may have to wait until you create a main form record.
Ok I tested, it worked in my case but could depend on how you have relational integrity set.
Done it!!! Thank you
Since Main Form opens, it creates a primary key, and takes some values as default. So record can be saved. I added a saverecord command before passing the open args value, and that was it!

Thank you all

You've been so helpful
 

Users who are viewing this thread

Top Bottom