0

I am designing some dynamic graphs and what I would like to do is after selecting the portfolio of interest from a ComboBox it would send the name/value of the portfolio to a SQL query to collect the data. At the moment after selecting the variable the Combo Box unloads the value to cell B1.

In the graph macro I define the variable, Selected_Portfolio, as a string and initiate it per

Selected_Portfolio = Range("B1").Value

The SQL statement is then written as

sqlStr = "select * from ( "
sqlStr = sqlStr & "select Top 30 PFDate, RiskValue from dbo.Portfolios "
sqlStr = sqlStr & "where PortName = ' & Selected_Portfolio & '"  
sqlStr = sqlStr & "order by PFDate desc) sub "
sqlStr = sqlStr & "order by PFDate"

The issue I have is that I do not believe I am passing Selected_Portfolio correctly. I know this because if the hard code PortName with a specific portfolio it works.

Thanks in advance

1 Answer 1

2

You are missing a couple of double quotes:

sqlStr = "select * from ( "
sqlStr = sqlStr & "select Top 30 PFDate, RiskValue from dbo.Portfolios "
sqlStr = sqlStr & "where PortName = '"  & Selected_Portfolio & "' "  
sqlStr = sqlStr & "order by PFDate desc) sub "
sqlStr = sqlStr & "order by PFDate"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.