Gather value from SQL based on value inside a cell

RoiPatrick

New member
Joined
Jul 9, 2013
Messages
1
Reaction score
0
Points
0
I would llike to ask anyone on how to complete this lind of code. I'm having a hard time completing the code. Actually, I would like SQL to throw data to excel based on the value placed in one of the cell (a1 for example). Here's my line of code and hope that anyone will help me. Thanks in advance anyway.

SQLStr1 = "SELECT ObjectiveDescription from Risk where RiskId =" ______________________<----what should I type next? I'm working on this for the past 2 weeks and still cannot find the right code for this one.

Information:

Table name in SQL is Risk
Primary Key is RiskId
Cell which has a value is "G1"
Objective description is one of the Columns inside risk table.


Thank you so much for the help.
 
Is RiskID a text or numerical value in the database?

Try this:

Code:
[COLOR=#333333]SQLStr1 = "SELECT ObjectiveDescription from Risk where RiskId = '"& Worksheets("Sheet1").Range("G1").Value & "'"

(Assumes it is on Sheet1, of course.)

If that doesn't work, try removing both ' characters from the line of code above (one before the "& and one between the two quotes at the end.)[/COLOR]
 
Back
Top