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: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.)
Ken Puls, FCPA, FCMA, MS MVP
Learn to Master Your Data at the Power Query Academy (the world's most comprehensive online Power Query training), with my book M is for Data Monkey, or our new Power Query Recipe cards!
Main Site: http://www.excelguru.ca -||- Blog: http://www.excelguru.ca/blog -||- Forums: http://www.excelguru.ca/forums
Check out the Excelguru Facebook Fan Page -||- Follow Me on Twitter
If you've been given VBA code (a macro) for your solution, but don't know where to put it, CLICK HERE.
Bookmarks