OpenArgs confusion

TB11

Member
Local time
, 22:47
Joined
Jul 7, 2020
Messages
81
Hi. I need to pass the IDOrder from the frmOrder to a new form frmOrderDetails, connected with foreign key fkOrder.

Typically, frmOrderDetails will be used for adding new records.

So I am confused as to what the code should be for both the command button on frmOrder and the On Loan event code on the frmOrderDetails, as I am not using the same ID name on each form.

I have tried to figure this out, but the more I read online, the more confused I get.

My goal: is to facilitate data entry, so I can go from one form to next, geared on ID to fk fields. (I really do not like tabbed forms and the subform approach is way too clunky.)

Thanks.
 
OpenArgs is the last parameter in the OpenForm command.
You could also set a Tempvar and check for that in a Form Open, but OpenArgs is the usual method.
 
Note that OpenArgs is passed like a string.


On Loan event code

Probably meant "On Load"? The BEST place to deal with an OpenArgs case is usually the OnOpen event because it is the first event you see for a form. You have time to "diddle" with settings in Form_Open and can even cancel the attempt to open the form if there is something wrong with the argument. In Form_Open, the internal structures have been opened but no structural things have been loaded yet. That is where Form_Load event becomes significant.

HOWEVER, there is a "gotcha" waiting to grab you. When you talk about this "command button", does it open the currently closed subform or is the subform already open and just waiting for a new fkOrder number to be provided? Your description "so I can go from one form to next, geared on ID to fk fields" could be construed as swapping between main and sub, which changes which events you would expect to see.

The method of subform activation makes a HUGE difference in terms of which event you need to use and whether OpenArgs even makes sense. Explain the procedural order of physical events (what you enter, when you navigate, what buttons you click, etc.) that you want to have happen because depending on what you are doing, it may be too late for OpenArgs to work.
 
Are you planning a single form view pop up to add only one new record or will the pop up allow multiple order details?
There are several things that may have to happen depending on how you want this to work. Can you show your main form and the desired pop up. Are you showing the details on the main form? Without a subform on the order form how do you show the order details in an intuitive manner?

In your command button you pass the OrderID in the docmd.openform method as the last parameter.

In the Pop ups beforeInsert Event you can do something
Code:
if (me.openargs & "") <> "" then me.fkOrder = me.openArgs

This will push the ID into the fk field for the pop up.
I would make the pop up dialog and not allow navigation on the form. It should be in add new mode.

subform approach is way too clunky
Since this is by far the easiest, most ensured, most common way to do it and IMO most intuitive what exactly is clunky? The capability of the subform control is anything but clunky. Coding that same functionality to filter, add new foreign keys would take a lot of code. The fact you can link to a field or an unbound control gives it a ton of flexibility. Are you sure you know how to use it, and know its limitations? The only thing I can think of is you have lots of memo fields limiting your real estate.

Not to be critical, but if you cannot figure out how to do a relatively simple pop up passing an argument do you really want to go a non standard route of adding a new record? It can be done with a pop up, but you are adding complexity, taking away functionality, and removing flexibility.
 
I use something like this to set the default value

frmOrder code to open frmOrderDetails:
Code:
Private Sub cmdOpenDetails_Click()
    DoCmd.OpenForm "frmOrderDetails", , , , , , Me.txtOrderID
End Sub

Code in the On Open event of frmOrderDetails:
Code:
Private Sub Form_Open(Cancel As Integer)
    If Len(Me.OpenArgs & "") > 0 Then
        Me.OrderID.DefaultValue = Me.OpenArgs
    End If
End Sub
 
(I really do not like tabbed forms and the subform approach is way too clunky.)
I'm not sure how clunky it is, but I think it's a simpler approach to use a popup form/subform in cases like these. Just my 2 cents...
 

Users who are viewing this thread

Back
Top Bottom