Results 1 to 5 of 5
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    method seek or find (6.0)

    I dont know if is correct to post here....

    admint i have MYmdb.mdb
    in internal of this database have myatbel1 and mytable2
    in the same table have a field named COPE

    now...

    from other vba macro (in excel using ADO) i fill MyVar with value.

    is possible to find in the 2 table and into filed COPE if existis the value assumed MyVar and is existis go to the next line of code

    similar:

    seek Myvar in rds1 in filed COPE
    existis ok
    goto next line
    not existis
    seek MyVar in rds2 in filed COPE
    existis ok
    goto next line

    hope undesrtand me...

    but, naturally other way are welcome...

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: method seek or find (6.0)

    It's not clear what you want to do. In all cases, whether the value is found or not, the code will continue with the next line, so why bother checking anything?

  3. #3
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: method seek or find (6.0)

    In effect, i want to scann if the value assigned to MyVar is present in the 2 field COPE of table1 and in filed COPE of table2, if the value of MyVar is present in one of this filed goto mymacro else got mymacro1...

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: method seek or find (6.0)

    Let's say that you open a recordset rst1 on the first table, and a recordset rst2 on the second table. You can use code like this:

    rst1.MoveFirst
    rst1.Find "COPE=" & Chr(34) & myVar & Chr(34)
    If rst1.EOF Then
    ' Not found in rst1, so search in rst2
    rst2.MoveFirst
    rst2.Find "COPE=" & Chr(34) & myVar & Chr(34)
    If rst2.EOF Then
    ' Not found in rst2 either
    Call myMacro2
    Else
    ' Found in rst2
    Call myMacro
    End If
    Else
    ' Found in rst1
    Call myMacro
    End If

    Alternatively, open a recordset rst1 on a union query:

    rst1.Open "SELECT COPE FROM myTable1 UNION SELECT COPE FROM myTable2", _
    cnn, adOpenKeyset, adLockOptimistic, adCmdText
    rst1.MoveFirst
    rst1.Find "COPE=" & Chr(34) & myVar & Chr(34)
    If rst1.EOF Then
    ' Not found
    Call myMacro2
    Else
    ' Found
    Call myMacro
    End If

    In the above code, cnn is the Connection object.

  5. #5
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: method seek or find (6.0)

    GOOD!!!!
    Tks.

Posting Permissions

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