LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Replace ActiveCell w/Query Results?


I'm as much of a noob as there can be, so please feel free to tell me
that I'm an idiot if that is the case. I'm trying to write a function
that will query an access database and return a value, based on a
number submitted in the function. The function would be entered into
excel as "=pktest(8)" and would then query a database and display a
name. I'm sure that I have made this more complicated than it is, but
can anybody help?

It works fine if I use a specific cell destination, such as
Destination:=Range("B1")

But when I try to use ActiveCell as the destination, I just get a
#VALUE!


Function pktest(pkvar)
Call pktest2(pkvar)
End Function

Sub pktest2(pkvar)
Dim pkvar2 As Integer
pkvar2 = 8
With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DSN=ccg;DBQ=C:\ccg.mdb;DriverId=25;FIL=M S
Access;MaxBufferSize=2048;PageTimeout=5;" _
, Destination:=ActiveCell)
..CommandText = "SELECT firstname FROM instructors WHERE
instructorid=" & pkvar
..Name = "Query from ccg_1"
..FieldNames = False
..RowNumbers = False
..FillAdjacentFormulas = False
..PreserveFormatting = False
..RefreshOnFileOpen = False
..BackgroundQuery = True
..RefreshStyle = xlInsertDeleteCells
..SavePassword = True
..SaveData = True
..AdjustColumnWidth = False
..RefreshPeriod = 0
..PreserveColumnInfo = False
..Refresh BackgroundQuery:=False
End With
End Sub




Thanks


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Replace VLOOKUP results with data Morto Kopor Excel Worksheet Functions 1 December 31st 07 07:25 AM
If activecell.column = variable then activecell,offset (0,1) Battykoda via OfficeKB.com Excel Discussion (Misc queries) 1 October 2nd 07 08:05 PM
how do i automatically replace formula with results Eric Excel Worksheet Functions 1 March 9th 06 06:11 PM
Find & Replace - view results Claes G Excel Discussion (Misc queries) 2 March 16th 05 10:55 PM
Web Query Sleep for until results come Sunil_Modi Excel Worksheet Functions 0 November 19th 04 04:29 PM


All times are GMT +1. The time now is 02:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"