Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2005
    Posts
    183

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

  2. #2
    Join Date
    Apr 2004
    Location
    Derbyshire, UK
    Posts
    789
    Provided Answers: 1
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •