KB-33811: Searching the last value recorded on a table, via scripts.

Question:

How can I have a script search for the last value that was recorded on a table?

Solution:

To do so, you must set up an SQL query that searches for the last value on the table.

With an Access database, you can use a query that is similar to the one below:

SELECT LAST(FieldName) as LastCod
FROM Table

With an SQL Server database, you can use a query that is similar to the one below:

SELECT Top 1 ([E3TimeStamp])
FROM Table
ORDER BY E3TimeStamp DESC

Once the query is set up in the application, you must create the script that will execute it and then manipulate the value returned by it via RecordSet.

An example of script can be this:

 

set QueryResult = Application.GetObject(“Data.Query1”).GetADORecordset()
LastValue = QueryResult.Fields(“LastCod”).Value

 

When executed, the last record remaining in the database table will be loaded into LastValue variable.
Print Friendly, PDF & Email

Este artigo foi útil? Was this helpful?

Classificação média - Average rating 0 / 5. Count: 0

Leave a Reply

Your email address will not be published.Required fields are marked *