title: Lambda Scope for query expressions
body: <p>This code works:</p>
  
  <pre><code>gErrorHandler.Push("frmItemcodes.cmdRunMethodOne_Click")
  If gfHANDEL_ERRORS Then On Error GoTo PROC_ERR
  
  Dim query = KQdbs.Items.Where(Function(f) f.Itemcode &gt; 8000)
  Me.dgvItemcodes.DataSource = query.ToList
  
  PROC_EXIT:
      gErrorHandler.Pop()
      Exit Sub
  
  PROC_ERR:
      gErrorHandler.HandleError()
      Resume PROC_EXIT
  </code></pre>
  
  <p>but if I change the literal 8000 to any kind of variable I get the following error:</p>
  
  <p>Error   BC36597 'On Error GoTo PROC_ERR' is not valid because 'PROC_ERR' is inside a scope that defines a variable that is used in a lambda or query expression.</p>
  
  <p>I have no idea why</p>
  
  <p>If I change the code in the body to this:</p>
  
  <pre><code>Dim query = From item In KQdbs.Items Where item.Itemcode = 8000
  Me.dgvItemcodes.DataSource = query.ToList
  </code></pre>
  
  <p>The results are the same, the literal works a variable returns the same error as above</p>