Your question is somewhat different but I think that the approach you need to follow will be more or less the same.
Main Topics
Browse All TopicsAll,
I am trying to pull a value from a SQL DB and pass it through to Cell E8 in Excel. Everything else works, but I am stuck on trying to get the value into the cell. I have tried using a Recordset, but either I am doing it wrong or Excel 2003 does not support it.
I appreciate any and all help.
Thanks,
Brad
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
You should use ADO to get your data:
http://www.exceltip.com/st
Leon
Excel 2003 won't allow me to use ADODB in my code. Being new to VBA I am not sure if it is something I am doing or if it is just the version I am using. I did find the answer I was looking for on another question from EE. I added the following under the first 'with' statement and it worked:
.CommandText = strsql
.Name = "Query from SQL SERVER"
.FieldNames = False
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery = True
Ok. I tried the ADODB, but I am lost now. Can one of you help me out? I have posted my code below, but keep in mind, this is only my second time writing VBA code so anything you write if you could give me an explanation of what is going on I would greatly appreciate it. The book I have does a horrible job at explaning working with databases...
Lets do this all in one procedure for now:
Private Sub ConnectToSQL()
Dim strSQL As String
Dim rs As ADODB.Recordset
Dim strDBPath As String, strTableName As String
Set conSQLDB = New ADODB.Connection
conSQLDB.Open "Server=SQL2005;DRIVER=SQL
" Office 2003"
AuditNum = Range("AuditNum")
ProfileNum = Range("ProfileNum")
AuditNum = "'" & AuditNum & "'"
ProfileNum = "'" & ProfileNum & "'"
strSQL = "Select cus.consignment " & _
" from cus_tbl_customer cus " & _
" join audit au on cus.cust_num = au.cust_num " & _
" where au.audit_num in (" & AuditNum & ")"
Set rs = New ADODB.Recordset
rs.Open strSQL, conSQLDB, adOpenStatic, adLockOptimistic
Range("E8").Value = rs!consignment
End Sub
Try this,
Leon
Business Accounts
Answer for Membership
by: sstampfPosted on 2009-10-19 at 09:43:23ID: 25606756
I answered a similar question few days ago and it was about pulling data from an excel file and inserting that into an access database. Check out the link, see if it helps you:
http://www.experts-exchang