Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Mar 2006
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    289
    Thanks
    0
    Thanked 1 Time in 1 Post

    Find last viewed record (2003 sp2)

    I wanted to open a continuous form and go to the last record entered or edited, and I found an article in the Microsoft knowledge base with sample code to do this. However, the code was based on the Customer table in the Northwind database with a CustomerID data type text. My table uses an auto number. The code gives an error at the line: rstFrm.FindFirst "[EntryID]='" & rst![Value] & "'" with the message invalid data type. EntryID is the AutoNumber field and Value is Long Integer. Where is the error?
    Thanks
    chuck

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

    Re: Find last viewed record (2003 sp2)

    The example assumes a text field; text values are enclosed in (single or double) quotes. Number values should *not* be enclosed in quotes, so try
    <code>
    rstFrm.FindFirst "[EntryID]=" & rst![Value]
    </code>
    (I removed the single quotes around rst![Value])

  3. #3
    3 Star Lounger
    Join Date
    Mar 2006
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    289
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Find last viewed record (2003 sp2)

    I modified the line as you suggested and it works as expected. Thank You. But why is EntryID enclosed in quotes when it is a number value?
    Thanks
    chuck

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

    Re: Find last viewed record (2003 sp2)

    The FindFirst method of the recordset takes a string (=text) argument that describes the search criteria. To take a simple example: to search for the record with EntryID 24, you'd use
    <code>
    rstFrm.FindFirst "[EntryID]=24"
    </code>
    The field name itself is not enclosed in quotes, the entire condition is. However, you don't want to search for a fixed EntryID value, but for a value that can change over time. This is accomplished by concatenating the fixed part of the condition [EntryID]= with a variable value rst![Value]. If rst![Value] equals 37 today,
    <code>
    rstFrm.FindFirst "[EntryID]=" & rst![Value]
    </code>
    evaluates to
    <code>
    rstFrm.FindFirst "[EntryID]=37"
    </code>
    and if it equals 55 tomorrow, it will evaluate to
    <code>
    rstFrm.FindFirst "[EntryID]=55"
    </code>
    I hope this clarifies things. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

  5. #5
    3 Star Lounger
    Join Date
    Mar 2006
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    289
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Find last viewed record (2003 sp2)

    I appreciate the explanation and the patience to give it.
    Thanks
    chuck

Posting Permissions

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