I am trying to dynamically refer to a variable name. I have multiple search variables:
condCity
condState
condZIP
condCustNum, etc....
Each one is an sql WHERE statement used in a rowsource assignment for a listbox. Example: rowsource = condCity & CondState & condZIP ... All variables need to be present at all times, but only one will change at a time, so I just want to redefine them on an as-needed basis by using the me.activecontrol.tag property. Currently I execute a series of If..then statements to check all the controls for null or changed values, but the coding is really redundant and I think I could clean it up signicantly if I could do what I'm attempting here.
My goal is to set the contents of each variable by telling VB "The variable I want to change has a prefix 'cond' & and a suffix that is the text of 'Me.ActiveControl.Tag'". I just can't find the right syntax. Here is my code:
***********************************
ButtonTag = Me.ActiveControl.Tag
sqlCond = "AND (qSearchCust." & ButtonTag & ") like '*' & forms!frmMainSearch!txt" & ButtonTag & " & '*') "
If IsNull(Me.ActiveControl) Then
cond & ButtonTag = ""
^^^^^^^^^^^^^^^^^^^ THIS IS THE PROBLEM SYNTAX HERE
Else: cond & ButtonTag = sqlCond
End If
sqlRowSource = condBase & condRegion & condSubRegion & condSubRegion & condKeyword & condCustNo & condCity & condState & condZIP & condStart & condEnd
Me.lstSearchCust.RowSource = sqlRowSource & sqlSort
****************************************************
Is it possible to dynamically refer to and define VB variables?
I've tried:
"cond" & buttontag = "mysql"
cond(buttontag) = "mysql"
cond + buttontag = "mysql"
Each gives me various errors. All of these assume that I've already defined buttontag as Buttontag = me.activecontrol.tag.
Any help would be greatly appreciated.
condCity
condState
condZIP
condCustNum, etc....
Each one is an sql WHERE statement used in a rowsource assignment for a listbox. Example: rowsource = condCity & CondState & condZIP ... All variables need to be present at all times, but only one will change at a time, so I just want to redefine them on an as-needed basis by using the me.activecontrol.tag property. Currently I execute a series of If..then statements to check all the controls for null or changed values, but the coding is really redundant and I think I could clean it up signicantly if I could do what I'm attempting here.
My goal is to set the contents of each variable by telling VB "The variable I want to change has a prefix 'cond' & and a suffix that is the text of 'Me.ActiveControl.Tag'". I just can't find the right syntax. Here is my code:
***********************************
ButtonTag = Me.ActiveControl.Tag
sqlCond = "AND (qSearchCust." & ButtonTag & ") like '*' & forms!frmMainSearch!txt" & ButtonTag & " & '*') "
If IsNull(Me.ActiveControl) Then
cond & ButtonTag = ""
^^^^^^^^^^^^^^^^^^^ THIS IS THE PROBLEM SYNTAX HERE
Else: cond & ButtonTag = sqlCond
End If
sqlRowSource = condBase & condRegion & condSubRegion & condSubRegion & condKeyword & condCustNo & condCity & condState & condZIP & condStart & condEnd
Me.lstSearchCust.RowSource = sqlRowSource & sqlSort
****************************************************
Is it possible to dynamically refer to and define VB variables?
I've tried:
"cond" & buttontag = "mysql"
cond(buttontag) = "mysql"
cond + buttontag = "mysql"
Each gives me various errors. All of these assume that I've already defined buttontag as Buttontag = me.activecontrol.tag.
Any help would be greatly appreciated.