+ Reply to Thread
Results 1 to 3 of 3

Lookup data in Oracle database

Hybrid View

  1. #1
    Registered User
    Join Date
    10-15-2008
    Location
    Netherlands
    Posts
    4

    Lookup data in Oracle database

    Hi
    I am trying to lookup data in an oracle table based on a value in my excel spreadsheet. I am using the DBVLOOKUP function that I found on Google, and am trying to convert the connection string to use an ORACLE connection.
    The code I have is as follows...

    Dim adoCN As ADODB.Connection
    Dim strSQL As String
    
    Public Function DBVLookUp(TableName As String, _
                              LookUpFieldName As String, _
                              LookupValue As String, _
                              ReturnField As String) As Variant
        Dim adoRS As ADODB.Recordset
        Set adoCN = New Connection
        adoCN.ConnectionString = "Provider=OraOLEDB.Oracle;Data Source=myTNSname;User Id=myuser;Password=mypass;"
        adoCN.Open
    
        Set adoRS = New ADODB.Recordset
        strSQL = "SELECT DISTINCT" & LookUpFieldName & ", " & ReturnField & _
                 " FROM " & TableName & _
                 " WHERE " & LookUpFieldName & "=" & LookupValue & ";"
                 
        adoRS.Open strSQL, adoCN, adOpenForwardOnly, adLockReadOnly
        If adoRS.BOF And adoRS.EOF Then
            DBVLookUp = "Value not Found"
        Else
            DBVLookUp = adoRS.Fields(ReturnField).Value
        End If
        adoRS.Close
    End Function
    The module does not show any errors, the SQL statement is correct, and it does seem to be connecting to the data. However I only get #value showing in my spreadsheet.
    The function on the spreadsheet looks like..
    =DBVLOOKUP("TableName","LookUpFieldName", $F$23,"ReturnField")
    where $F$23 is the cell that is being referenced for lookup in the Oracle DB.

    I cant see what's going wrong , if someone could point me in the right direction that would be a great help.

    Thx

  2. #2
    Registered User
    Join Date
    06-12-2008
    Location
    Newbury
    MS-Off Ver
    Office 365 ProPlus
    Posts
    92
    I seem to recall that you can't do this with a UDF called from the worksheet. UDF's called from a worksheet are limited in what they can do see http://support.microsoft.com/kb/170787 for more details.

  3. #3
    Registered User
    Join Date
    10-15-2008
    Location
    Netherlands
    Posts
    4
    Thx for the reply chergh, but just so that I am clear on this, whats the difference between this function working with Access and not being able to work with Oracle?
    There is no modification to the sheet, it's just a lookup function to return some values based on a user's entry in one cell.
    Thx

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Lookup Data Range for Quarter Periods
    By kasimagj in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 06-12-2008, 04:02 AM
  2. How to create dependent lists from database data
    By V1su in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-28-2008, 04:44 AM
  3. Various macro issues linked to DDE
    By JMann in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-16-2008, 08:08 AM
  4. Replies: 2
    Last Post: 02-14-2008, 05:02 PM
  5. lookup with repeating data in column a
    By kiki_lallissee in forum Excel General
    Replies: 5
    Last Post: 02-26-2007, 04:48 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1