+ Reply to Thread
Results 1 to 4 of 4

Comparing sql record to cell value

  1. #1
    Registered User
    Join Date
    08-18-2004
    Posts
    15

    Comparing sql record to cell value

    I am assigning a value to a variable from an oracle query using 0040 and a dynaset.

    Eg For i = 1 To OraDynaSet.RecordCount
    dbValue = OraDynaSet.Fields(0).Value
    ............................ bla bla


    I am then trying to compare this variable with some value in a range and am getting in all sorts of a mess with Exit For, End If

    What I am trying to do is getting first record and compare to every value in my range eg Range("A1:A3"). If it find a value then good and we move onto next record. If it does not find a matching value then up pops a msgbox and procedure stops. If all records from query are matched in the range then naturally it also stops or does something else without any problems


    Thanks
    Last edited by mozart; 06-07-2005 at 07:38 AM.

  2. #2
    Forum Contributor
    Join Date
    06-10-2004
    Location
    India
    Posts
    1,066
    if not (WorksheetFunction.Match(dbValue,range("A1:A3"),0) > 0) then
    msgbox "your message here"
    exit sub
    end if


    Mangesh

  3. #3
    Forum Contributor
    Join Date
    06-10-2004
    Location
    India
    Posts
    1,066
    Sorry, when not found, the match gives an error. You may use something like this instead:

    Sub Test()

    On Error GoTo Err_handler
    a = WorksheetFunction.Match(2, Range("A1:A3"), 0)

    ' your code here

    Err_handler:
    Exit Sub

    End Sub



    Mangesh

  4. #4
    Forum Contributor
    Join Date
    06-10-2004
    Location
    India
    Posts
    1,066
    A better approach:

    Sub test()

    Set a = Range("a1:a3").Find(dbValue, LookIn:=xlValues)

    If a Is Nothing Then
    MsgBox "not found"
    Exit Sub
    End If

    End Sub


    Mangesh

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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