Move Combo Box selection If one to another form (1 Viewer)

oxicottin

Learning by pecking away....
Local time
Today, 00:57
Joined
Jun 26, 2007
Messages
856
I have a form (frm_Main) that has a combo box (cboEmployee). I want to bring the selected of that combo box if there is one to another form (frm_Test) combo box (cboEmployee) if there is a value and have it selected. Basically like a default name if there is one in (frm_Main) (cboEmployee).

Here is what I have started in the (frm_Test) current:

Code:
Private Sub Form_Current()
Dim strSQL As String
                   
strSQL = "SELECT tbluEmployees.EmployeeID, [EmpLName] & "", "" & [EmpFName] AS EmployeeName, tbluEmployees.IsInactive, tbluEmployees.SupervisorID " & vbCrLf & _
         "FROM tbluEmployees " & vbCrLf & _
         "WHERE (((tbluEmployees.IsInactive)=False) AND ((tbluEmployees.SupervisorID)=[Forms]![frm_ReportSelection]![txtCurrentSelectedSupervisor])) " & vbCrLf & _
         "ORDER BY [EmpLName] & "", "" & [EmpFName];"

    If IsNull([Forms]![frm_YearCalendar]![cboEmployee]) Then
        Me.cboEmployee.RowSource = strSQL
    Else
'How do I get [Forms]![frm_YearCalendar]![cboEmployee] rowsource to show the selected value in the combo box?
   End If
End Sub
 

Gasman

Enthusiastic Amateur
Local time
Today, 05:57
Joined
Sep 21, 2011
Messages
14,238
I would pass the value in via OpenArgs, and if present set the combo value.?
 

oxicottin

Learning by pecking away....
Local time
Today, 00:57
Joined
Jun 26, 2007
Messages
856
Thanks again Gasman, I never used OpenArgs and now I know a little about it...

On Form 1
Code:
'Pass value of combo box using OpenArgs
    DoCmd.OpenForm FormName:="frm_ReportSelection", OpenArgs:=Me.cboEmployee.Value

On Form 2
Code:
Private Sub Form_Load()
    If Me.OpenArgs & "" <> "" Then
    [Forms]![frm_ReportSelection]![cboEmployee] = CLng(Me.OpenArgs)
    End If
End Sub
 

Gasman

Enthusiastic Amateur
Local time
Today, 05:57
Joined
Sep 21, 2011
Messages
14,238
I would not have thought there was any need for the CLng() function.? Nor the forms reference?, just Me.

I have never had to use it when I have been doing the same?:unsure:
 

oxicottin

Learning by pecking away....
Local time
Today, 00:57
Joined
Jun 26, 2007
Messages
856
Didn't really know what I was doing being my first time with OpenArgs. I found an example and ran with it...
 

Users who are viewing this thread

Top Bottom