View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Roger[_8_] Roger[_8_] is offline
external usenet poster
 
Posts: 12
Default Passing SQL Query Result Into A Variable

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......

HT
Roge
Shaftesbury (UK

----- Elliot wrote: ----

Hi readers

I am using Excel 2000 VBA to run a quick query. I am hoping to provid
my SQL server with an account number, for which it will reply with th
relevant customer's name

A snippet of my code looks like this

'------------------------------------------------------------
Dim Msg As String, Cust_Ref As Strin

Msg = "Please enter customer reference

Cust_Ref = UCase(InputBox(Msg, "User Request")

With ActiveSheet.QueryTables.Add(Connection:=
"ODBC;DRIVER={Transoft ODB
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.S
SL" & Chr(13) & "" & Chr(10) & "WHERE (SL.slc_ref='" & Cust_Ref
"')"
.Name = "Query from Server
.FieldNames = Fals
.RowNumbers = Fals
.FillAdjacentFormulas = Fals
.PreserveFormatting = Tru
.RefreshOnFileOpen = Fals
.BackgroundQuery = Tru
.RefreshStyle = xlInsertDeleteCell
.SavePassword = Tru
.SaveData = Tru
.AdjustColumnWidth = Tru
.RefreshPeriod =
.PreserveColumnInfo = Tru
.Refresh BackgroundQuery:=Fals
End Wit

'------------------------------------------------------------

At first, I tried replacing

Destination:=Range("A1"))

wit

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 usin
Excel VBA for years, as well as maintaining/programming a compan
PROGRESS 4GL v8.2c database system

Ellio