Way to know form name that opens a particular form (1 Viewer)

Babycat

Member
Local time
Tomorrow, 03:35
Joined
Mar 31, 2020
Messages
275
Dear all

I have formA and formB that both contain combobox Cbx_Footprint.
User can click on "Edit item list" to open other form (formC) for adding new Items.

When closing formC, I would like to requery Cbx_Footprint to have latest Items likely:
Code:
Forms!FormA.Cbx_Footprint.requery

However I dont know formA or formB is active for appropriate combobox requery...
I can't set form OpenArg of formC since it is opeing from combobox click.

Any advice please?


1688847841483.png
 
Last edited:
Hi
In the properties of the Combobox on FormA
On the Event Tab - Select On Enter
Then put :- "Me.NameofCombobox.Requery"

Same for FormB
 
If I'm following you correctly I think you want to test for .IsLoaded

Code:
If CurrentProject.AllForms("FormA").isloaded then
     Forms("FormA").YourComboName.Requery
End if

Same for FormB

Why not NotInList event?
 
Last edited:
Hi
In the properties of the Combobox on FormA
On the Event Tab - Select On Enter
Then put :- "Me.NameofCombobox.Requery"

Same for FormB
Hi Mike
That is a working solution.
However, formA has servaral Combobox and we rarely edit items on formC thus I personally dont want many redundant requery action of these Comboboxes. (Form may be flashing on requery action as well)
 
If I'm following you correctly I think you want to test for .IsLoaded

Code:
If CurrentProject.AllForms("FormA").isloaded then
     Forms("FormA").YourComboName.Requery
End if

Same for FormB

Why not NotInList event?

Hi Moke

It works in case formA, formB is standalone. In fact, my formA is a subform then the code CurrentProject.AllForms("FormA").isloaded always returns False.
Furthermore, It is a bit manually, if later I have formA1, formA2 with same scenario, I will have to add these code again... what I can easily forget to do so.

Why not NotInList event? How do you use it in this case?
 
Could both form A and B be a single form, possibly with different items visible depend on conditions set using OpenArgs on similar.
It shouldn't matter whether it is standalone or a subform.

If so, you no longer have a problem to solve.
 
The problem with your question is that an opened form neither knows nor cares how it was opened.

I personally dont want many redundant requery action of these Comboboxes. (Form may be flashing on requery action as well)

This is going to be inconsistent with your goal. There is a general rule in programming that if you want to know something about how you started, have the thing that started you pass that info along. Opening a form opens a child window but the catch is that it is normally an independent child. There is no dependency between them at the Windows child process level. They ALL have MSACCESS.EXE's process as their parent.

Using an "OpenArgs" operation to pass Me.Name as an argument to the form is the easiest way to know. If there is a click event for that combo box, why do you think you can't put an OpenArgs reference there when you click? There IS, after all, a click event just sitting there.
 
The problem with your question is that an opened form neither knows nor cares how it was opened
That is incorrect in the case of a form opened through ListItemsEditForm, because they have a reference in the OpenArgs argument.

So, if FormC is opened via that property, you can do this in FormC:
Code:
Private Sub Form_Open(Cancel As Integer)
    MsgBox Me.OpenArgs
End Sub

And it will return the aforementioned reference to the control that opened it with this syntax: [TheForm]![TheControl]=

You can then extract that reference and use it in any way you prefer, like:
Code:
Private Sub Form_Close()
    If InStr(Me.OpenArgs, "FormA") > 0 Then
        Forms.FormA.cboFormA.Requery
    ElseIf InStr(Me.OpenArgs, "FormB") > 0 Then
        Forms.FormB.cboFormB.Requery
    End If
End Sub
 
Last edited:
I'm not quite clear on your question, but I think what you're saying is you want both combobox Row sources to update at the same time, whether you add a new item in one of the combo boxes or a new item in the other combo box. I've done demo database and here's a video of it.

Update Combo Row Source - Nifty Access​

 
Using an "OpenArgs" operation to pass Me.Name as an argument to the form is the easiest way to know. If there is a click event for that combo box, why do you think you can't put an OpenArgs reference there when you click? There IS, after all, a click event just sitting there.
Hi
The Combobox_Click event does not fire when you click on "Edit List Item" of combobox, thus I still can't configure out how to pass the argument "Me.Name" to formC. So, formC does not know how it was opened. This is my problem.
 
Last edited:
I'm not quite clear on your question, but I think what you're saying is you want both combobox Row sources to update at the same time, whether you add a new item in one of the combo boxes or a new item in the other combo box. I've done demo database and here's a video of it.

Update Combo Row Source - Nifty Access​

Hi Nifty,
Thank for making the video, I have learnt alot from your youtube channel.
My concern is in the case we have many form + subform (for example FormB1 - subformA1, FormB2 - subformA2...) what employ same combobox Cbx_Footprint.
So, in the AfterUpdate event of frmFootprint, how do you determine B1-A1 or B2-A2 to be requery?

My form is required not having button "Edit combo list" like your video but we open form frmFootprint by clicking last row "Edit List Item" of Combobox.
 
However I dont know formA or formB is active
So what you are saying is formA or formB might be closed.

Therefore the code fails and causes an error when you try to re-query the combo box on a closed form.

A further complication is that you are trying to re-query a subform and is not possible to test to see if a subform is open?

I have questions:-
1) All of these forms and subforms are within one MS Access front end database used by one person? (Other users have their own front end)

2) you can have many forms open
we have many form + subform (for example FormB1 - subformA1, FormB2 - subformA2...)
And some are opened and others closed, so you never know which form(s) may or may not be open, or may or may not be closed?

3) The form to edit the list MUST be opened from the edit list item property of the combo box.

4) do you require the edit form to open in the case of a not in list event being triggered?

If that's the case then I'm thinking the code in frmFootprint (your form named formC) could be modified to scan through the form collection, find any open main forms, (mainform refers to the form that carries the subform) look in the forms it finds to see if it has the combo box cbx_footprint and re-query it. And then look to see if there is a subform containing the same combo box "cbx_footprint" and requery that.
 
Why can you not just requery in the form that called Form C.
I would also ask why not use the NotInList event?
 
So what you are saying is formA or formB might be closed.

Therefore the code fails and causes an error when you try to re-query the combo box on a closed form.

A further complication is that you are trying to re-query a subform and is not possible to test to see if a subform is open?

I have questions:-
1) All of these forms and subforms are within one MS Access front end database used by one person? (Other users have their own front end)

2) you can have many forms open

And some are opened and others closed, so you never know which form(s) may or may not be open, or may or may not be closed?

3) The form to edit the list MUST be opened from the edit list item property of the combo box.

4) do you require the edit form to open in the case of a not in list event being triggered?

If that's the case then I'm thinking the code in frmFootprint (your form named formC) could be modified to scan through the form collection, find any open main forms, (mainform refers to the form that carries the subform) look in the forms it finds to see if it has the combo box cbx_footprint and re-query it. And then look to see if there is a subform containing the same combo box "cbx_footprint" and requery that.
Hi Nifty
Therefore the code fails and causes an error when you try to re-query the combo box on a closed form. -->Yes, this is the keypoint of my issue.
1) All of these forms and subforms are within one MS Access front end database used by one person? - One FE, one person
2) you can have many forms open- Not really, one at time ex: (B1A1 open, B2A2 closed) or visa versa
3) The form to edit the list MUST be opened from the edit list item property of the combo box. - Yes, i dont want an extra button to open edit form
4) do you require the edit form to open in the case of a not in list event being triggered? - Yes, user just needs to click on "Edit List Item" which is the last row of combobox
 
I can't set form OpenArg of formC since it is opeing from combobox click.

how is form C being opened?

I only know of docmd.openform, a 'click runs code which would run the openform method.

Without fully understanding the requirement and why you cannot simply pass the name of the form/control as an openarg to openform have you considered using in the open event of form C to retrieve the screen.activecontrol.name for the control and acreen.activecontrol.parent.name for the form?

if your combo is on a subform, that would only provide the sourceobject of the subform control, so you would need a routine to keep going up the 'parents' until there are no more parents so you are on the main form
 
Why can you not just requery in the form that called Form C.
We dont know which the form name called formC... since formC is opened from combobox. And my topic goal is to know this form name...
I would also ask why not use the NotInList event?
Does it require extra work from user? User must to enter a wrong item to trigger NotInList event?
 
For clarity item 4, when a user types in the combo box something which isn't in the list, the "not in list event" offers the opportunity to save what you have typed in the editing form so you don't have to retype your entry. Please confirm...
 
For clarity item 4, when a user types in the combo box something which isn't in the list, the "not in list event" offers the opportunity to save what you have typed in the editing form so you don't have to retype your entry. Please confirm...
No, user will not type in anything, they use mouse to select an existing item, if the desired item is NOT existed, they will click on "Edit List Item" to open formC.
After they adding new item (called ItemX) on formC, they close formC and back to combobox, at this time the combobox should have ItemX. (that is why i need to requery combobox)
 
So if you open FormC in dialog mode, you need to close that to get back to the calling form and then requery the combo?
 

Users who are viewing this thread

Back
Top Bottom