You're still struggling with the ActiveControl thing?
You can refer to it as a Control object:
Dim ctl As Control
Set ctl = Screen.ActiveControl
Or you can refer to it as a string:
Dim strCtl As String
strCtl As String
strCtl =Screen.ActiveControl.Name
Your further question is a large one. Sounds like you need to be able to
build query strings on the fly. You do know that you can mock up a query,
switch it to SQL View, and copy what you see there? Beyond that, it's
important to include the # as the delimiter for date fields, and the " as
the delimiter for text fields, or perhaps BuildCriteria() can do that for
you.
For the example you specified, if you have a combo on the Switchboard form,
and the user can select 1 of the 4 text values, you would do something like
this in the Open event of your form:
Private Sub Form_Open(Cancel As Integer)
Dim strSql As String
Const strcStub = "SELECT * FROM MyTable "
Const strcTail = " ORDER BY SomeField;"
If CurrentProject.AllForms("Switchboard").IsLoaded Then
With Forms("Switchboard")!MyCombo
If Not IsNull(.Value) Then
strSql = strcStub & "WHERE [SomeField] = " & .Value &
strcTail
End If
End With
End If
If Len(strSql) = 0 Then
strSql = strcStub & strcTail
End If
Me.RecordSource = strSql
End Sub
Note that if SomeField is a Text type field (not a Number type field) it
needs the extra quotes around the value:
strSql = strcStub & "WHERE [SomeField] = """ & .Value & """" & strcTail