Findlast

User avatar
Steve_in_Kent
4StarLounger
Posts: 419
Joined: 04 Feb 2010, 11:46

Findlast

Post by Steve_in_Kent »

Im trying to compare an internal table, with an external file.

So far my code is:-

Code: Select all

strFind = "[Description] = " & Chr(34) & CincDesc & Chr(34)

With rs
.FindLast strFind
    
temp = .Fields("Description")
temp1 = .Fields("CurrentBOM")

End With
Description = the field name in the stored table ("BOM")
CincDesc = the string, brought in from the external file.

This, will find the last record in the table, that matches, the field in the external table.. however, this only matches on one parameter.
I need to match on 3 parameters. ie, the last record in the table, where 3 of the records, exactly, match 3 strings from the external file.
and, if it fails to find a match, i need to divert to other code.

I cannot find any code with .Findlast, to suggest it can do multiple parameters???
----------------------------------------------------------------------------------------
Owing at LEAST 34 beers to other helpful forum members. Especially HansV!

User avatar
HansV
Administrator
Posts: 78556
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Findlast

Post by HansV »

Steve_in_Kent wrote:... ie, the last record in the table, where 3 of the records, exactly, match 3 strings from the external file...
Do you meant 3 of the fields? If so, you can use something like this:

strFind = "[Description] = " & Chr(34) & CincDesc & Chr(34) & " AND [NumberField] = " & NumberVar & " AND [DateField] = #" & Format(DateVar, "mm/dd/yyyy") & "#"

You must, of course, substitute the appropriate names, and take the data types into account.
Best wishes,
Hans

User avatar
Steve_in_Kent
4StarLounger
Posts: 419
Joined: 04 Feb 2010, 11:46

Re: Findlast

Post by Steve_in_Kent »

thanks hans will give it a bash :clapping:
----------------------------------------------------------------------------------------
Owing at LEAST 34 beers to other helpful forum members. Especially HansV!

User avatar
Steve_in_Kent
4StarLounger
Posts: 419
Joined: 04 Feb 2010, 11:46

Re: Findlast

Post by Steve_in_Kent »

using some chr(34)#s this seems to work ok.. however...

is there anyway to trap, when it doesn't find a match >?

steve
----------------------------------------------------------------------------------------
Owing at LEAST 34 beers to other helpful forum members. Especially HansV!

User avatar
HansV
Administrator
Posts: 78556
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Findlast

Post by HansV »

Yes:

Code: Select all

With rs
  .FindLast strFind
  If .NoMatch Then
    MsgBox "No matching record found.", vbExclamation
    ' Optional: exit procedure
    Exit Sub
  Else
    temp = .Fields("Description")
    temp1 = .Fields("CurrentBOM")
  End If
End With
Best wishes,
Hans

User avatar
Steve_in_Kent
4StarLounger
Posts: 419
Joined: 04 Feb 2010, 11:46

Re: Findlast

Post by Steve_in_Kent »

your a star hans tyvm :hairout: :grin:
----------------------------------------------------------------------------------------
Owing at LEAST 34 beers to other helpful forum members. Especially HansV!