Named Range Breaks Code

Posted by Daniel on Stack Overflow See other posts from Stack Overflow or by Daniel
Published on 2010-05-13T16:53:02Z Indexed on 2010/05/13 21:24 UTC
Read the original article Hit count: 206

Filed under:
|
|

I have one workbook with several sheets. I populate the listboxes (pulling static data from cells) on the 2nd sheet, click a button and it runs fine.

When I populate the listboxes with a named range, the listbox populates the way I want, but I get an error because the code thinks that I didn't select anything in the listbox, even though I did. So it passes through "" instead of "title".

Is this a common issue? The named range isn't a problem because it passes through the data to the listbox and I know it's selecting data because as soon as the listbox loses focus, it spits out the contents of the cell into cell A1.

What's even stranger is that I have the contents of the listbox set to Msg1. So A1 gets populated with Msg1 (what I actually selected in the listbox). But when I try and use Msg1 in the code, it tells me that Msg1 is "". Again, this only happens when I use the dynamic named range, not with static data in cells K1:K9.

Private Function strEndSQL1 As String

Dim strSQL As String

strSQL = ""
        'Create SQL statement
    strSQL = "FROM (SELECT * FROM dbo.Filter WHERE ID = " & TextBox1.Text & " And Source IN (" & Msg1 & ")) a FULL OUTER JOIN "
    strSQL = strSQL & "(SELECT * FROM dbo.Filters WHERE ID = " & TextBox2.Text & " And Source IN (" & Msg1 & ")) b "
    strSQL = strSQL & "ON a.Group = b.Group    
strEndSQL = strSQL

End Function

© Stack Overflow or respective owner

Related posts about excel-vba

Related posts about vba