If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Grrr, function not returning a value to cell

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-12-06, 07:57
Trinsan Trinsan is offline
Registered User
 
Join Date: Oct 2005
Posts: 168
Grrr, function not returning a value to cell

I have the below function added to "this workbook" in order to fetch a number from a local SQL-Server database based on a value (typicaly from another cell).

Well, if I call the function in a form button, I get a return value, which is correct.

But, if I use the function in a cell, nothing happens...

Am I missing something obvious? I must admit I've never made use of functions this way, always through forms etc. so quite possible I'm missing something :-)

Cheers, Trin


Code:
Function FindGID(IPD As Variant)

    Dim GIDdns As New ADODB.Connection
    Dim ipdnParam As New ADODB.Parameter
    Dim GIDrs As ADODB.Recordset
    Dim kommando As New ADODB.Command
    
    GIDdns =my dns info
    GIDdns.Open
    
    ipdnParam.Type = adInteger
    ipdnParam = IPD
   
    kommando.ActiveConnection = GIDdns
    kommando.CommandText = "ket.EXCEL_IPDfind"
    kommando.CommandType = adCmdStoredProc
    kommando.Parameters.Append ipdnParam

    Set GIDrs = kommando.Execute
    
    FindGID = GIDrs!medlemsnummer
    
    GIDdns.Close

End Function
__________________
IT squid: networks, servers, firewalls, routers and I dabble a little with SQL-server and Access as well....
Reply With Quote
  #2 (permalink)  
Old 10-12-06, 08:57
MikeTheBike MikeTheBike is offline
Registered User
 
Join Date: Apr 2004
Location: Derbyshire, UK
Posts: 714
Hi

I believe functions need to be located in a separate 'Module' (not ThisWorkbook) for them to work in cells (don 't ask me why).

MTB
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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