title: SSRS Report Builder 3.0 - Why can't I use a code function as the source expression of a Lookup Function?
body: <p>I've built a report in Report Builder 3.0 that has a couple of hundred cells that perform Lookup functions in my datasets.  Obviously, with the number of cells, I would like to be able to create the expressions dynamically. I've been able to utilize the textbox names to do this with the following function:</p>
  
  <pre><code>Public Function TextBoxName(ByVal meString As String) As String
   Dim s As Integer = 19
   Dim e As Integer = meString.IndexOf(“_TextBoxExprHost”) – 19
   TextBoxName = meString.Substring(s,e)
   End Function
  
  Expression:
   =Code.TextBoxName(Me.ToString)
  </code></pre>
  
  <p>The above expression works as needed everywhere in the report except when I want to use it in a source expression in a Lookup function.  Here is an example:</p>
  
  <pre><code>Iif(IsNothing(Lookup((Code.TextBoxName(Me.ToString) &amp; "R"),Fields!SECTION_STATUS.Value,Fields!LCTN_COUNT.Value, "Loads")),"0",Lookup((Code.TextBoxName(Me.ToString) &amp; "R"),Fields!SECTION_STATUS.Value,Fields!LCTN_COUNT.Value, "Loads"))
  </code></pre>
  
  <p>The above example will compile but produces a #Error in the cell when I run the report. But, the report works as needed if I hardcode the textbox name for each of the source expressions.</p>
  
  <pre><code>"AP1010R" instead of Code.TextBoxName(Me.ToString) &amp; "R"
  </code></pre>
  
  <p>I've found no examples of anyone using custom code to generate this source expression.  Anyone have any ideas what could be going on here?  Thanks in advance.</p>