Open form on combobox after update event and set combobox selection on opened form

zulu100

Member
Local time
Today, 07:42
Joined
Nov 3, 2021
Messages
54
Hi
I have a (frm_Main) with one combo box "cbm_Main". In the combo box after update event I would like to open (frm_List) which also have a combo box "cbm_List"
Both combo boxes has the same control source "qry_Departments" and the bound column is 1. The content are numeric values.
I would like frm_List to open with the same combo box selection as I choose on frm_Main, but I cant seem to get the where condition syntax correct.
Something like:
docmd.OpenForm "frm_List",acNormal,, <cbm_Main=cbm_List>
 
Try using the OpenArgs argument.
 
add code to the Load Event of frm_List:
Code:
'arnelgp
Private Sub Form_Load()
' check if frm_main is open
If syscmd(acSysCmdGetObjectState,acform,"frm_Main") <> 0 Then
    'check if combobox on frm_main has a valid item on it
    If Forms!frm_Main!cbm_Main.ListIndex > -1 Then
        'assign it to this local combobox
            Me!cbm_List = Forms!frm_Main!cbm_Main
    End If
End If
End Sub
 
Last edited:
add code to the Load Event of frm_List:
Code:
'arnelgp
Private Sub Form_Load()
' check if frm_main is open
If syscmd(acSysCmdGetObjectState,acform,"frm_Main") <> 0 Then
    'check if combobox on frm_main has a valid item on it
    If Forms!frm_Main!cbm_Main.ListIndex > -1 Then
        'assign it to this local combobox
            Me!cbm_List = Forms!frm_Main!cbm_Main
    End If
End If
End Sub
Thanks arnelgp
That worked great
 
that was the intention (see post#1).
your post #7, will it not dirty the form? you know better.

be happy that the OP achieved what he want.
don't be a bitter gourd.
 
Sorry if I caused an issue here, this was certainly not my intention.
@Pat Hartman you are right. My knowledge about VBA is very limited and I grab a little bit from here and there to put my database together. In this case maybe I should have been more specific.
The combo-box on the opened form (frm_List) is actually a filter showing production orders for different department. In a test period I only had one department using the database and therefore the on open event was set to this one specific department. Now this is being rolled out to other departments I needed a Main form from where to choose which list of productions orders to see. This can also be done from the combo-box in "frm_List" but it is more user friendly to do it on a main form.
The combo boxes has the same source so they will always be identical even when new departments are added. So to my limited knowledge I think both @arnelgp and @Pat Hartman's will work OK, but I could be wrong :)
Thanks.
 

Users who are viewing this thread

Back
Top Bottom