Function GetControlName(ctl As Control) As String
GetControlName = ctl.Name
End Function
Function GetFormControl(strForm As String, strControl As String) As Object
Set GetFormControl = Forms(strForm).Controls(strControl)
End Function
Sub Sample()
MsgBox GetControlName(GetFormControl("Form1", "txtBox"))
End Sub
ToComplicated.PNGASKER
ASKER
ASKER
ASKER
Function ListBoxIn(lst As Object, Optional lngCol As Long = 0, Optional strDelim As String = "", Optional lngItem As Long) As String
If lngItem = -1 Then lngItem = lst.ItemsSelected.Count
If lngItem Then ListBoxIn = ListBoxIn(lst, lngCol, strDelim, lngItem - 1) & ListBoxIn & IIf(lngItem - 1, ",", "") & strDelim & lst.Column(lngCol, (lngItem - 1)) & strDelim
End Function
ASKER
Function ListBoxIn(lst As Object, Optional lngCol As Long = 0, Optional strDelim As String = "", Optional lngItem As Long = -1) As String
If lngItem = -1 Then lngItem = lst.ItemsSelected.Count
If lngItem Then ListBoxIn = ListBoxIn(lst, lngCol, strDelim, lngItem - 1) & ListBoxIn & IIf(lngItem - 1, ",", "") & strDelim & lst.Column(lngCol, lst.ItemsSelected(lngItem - 1)) & strDelim
End Function
ASKER
SELECT tblX10.X10
FROM tblX10
WHERE (tblX10.X10) In (ListBoxIn([Forms]![frmListBox]![List1]));
ASKER
ASKER
SELECT [tblX10].[X10]
FROM tblX10
WHERE ([tblX10].[X10]) In (ListBoxIn([Forms]![frmListBox]![lstBox]));
ASKER
ASKER
SELECT tblX10.X10
FROM tblX10
WHERE ((tblX10.X10) In (ListBoxIn(CallByName([Forms]![frmListBox],"lstBox",2))));
ASKER
ASKER
ASKER
ASKER
ASKER
Function ListBoxIn(lst As Object, lngCol As Long, strDelim1 As String, strDelim2 As String, lngItem As Long): On Error Resume Next: ListBoxIn = ListBoxIn(lst, lngCol, strDelim1, strDelim2, (lngItem - 1)) & ListBoxIn & IIf(lngItem - 1, strDelim1, "") & strDelim2 & lst.Column(lngCol, lst.ItemsSelected(lngItem - 1)) & strDelim2: End Function
Function ListBoxIn(R, i, c, k, ²): On Error Resume Next: ListBoxIn = ListBoxIn(R, i, c, k, (² - 1)) & IIf(² - 1, c, "") & k & R.Column(i, R.ItemsSelected(² - 1)) & k: End Function
ASKER
ASKER
Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.
TRUSTED BY
Do you mean a control Object? Or a control name ?
One issue is here:
Function GetControlName(ctl As Control) As String
Your argument is an Object but from the query you are passing a string "Form1", etc
SELECT CustomerID, CustomerName, GetControlName(GetFormCont