Passing SQL Query Result Into A Variable
Having re-read your post (sorry), probably best to try Recordset Method
Ensure your pointer is at the first (hopefully only) record. Then reference
the appropriate Fields, eg:
myRecordset.MoveFirst
Cust_Ref = myRecordset.Fields("name")
I can post Connection/Recordset examples tomorrow from my work PC.
--
HTH
Roger
Shaftesbury (UK)
"Roger" wrote in message
...
Hi Elliot,
Destination:=Range("A1"))
.....is where the results will be delivered to. Would it not work like
that? It looks as if it should do.......
HTH
Roger
Shaftesbury (UK)
----- Elliot wrote: -----
Hi readers,
I am using Excel 2000 VBA to run a quick query. I am hoping to
provide
my SQL server with an account number, for which it will reply with
the
relevant customer's name.
A snippet of my code looks like this:
'-------------------------------------------------------------
Dim Msg As String, Cust_Ref As String
Msg = "Please enter customer reference"
Cust_Ref = UCase(InputBox(Msg, "User Request"))
With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DRIVER={Transoft ODBC
Driver};TSDSN=dbasename.udd;Server=server;Port=700 0;Timeout=3600;Description
=;"
_
, Destination:=Range("A1"))
.CommandText = Array( _
"SELECT SL.slc_name" & Chr(13) & "" & Chr(10) & "FROM root.SL
SL" & Chr(13) & "" & Chr(10) & "WHERE (SL.slc_ref='" & Cust_Ref &
"')")
.Name = "Query from Server"
.FieldNames = False
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
'-------------------------------------------------------------
At first, I tried replacing
Destination:=Range("A1"))
with
Destination:=Cust_Ref)
But it didn't work. :-(
Any help would be appreciated!
Thanks in advance!
P.S. I'm relatively new to SQL via Excel 2000, but have been using
Excel VBA for years, as well as maintaining/programming a company
PROGRESS 4GL v8.2c database system.
Elliot
|