Can U Just Tell Me The Query To Get A Field From The Last Line Of The Table From Access Data Base
Printable View
Can U Just Tell Me The Query To Get A Field From The Last Line Of The Table From Access Data Base
Gets the First/Top:
select top 1 * from TABLE_NAME
Gets the Last:
select top 1 * from TABLE_NAME order by FIELD_NAME desc
This is all relative to the Order By though.... You need to have a primary key that you can sort on....
You can use MoveLast
VB Code:
Option Explicit Private objConn As ADODB.Connection Private objRs As ADODB.Recordset Private Sub OpenDBConnection() Set objConn = New ADODB.Connection objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\myFile.Mdb" End Sub Private Sub CloseDBConnection() If Not objConn Is Nothing Then If objConn.State = adStateOpen Then objConn.Close Set objConn = Nothing End If End Sub Private Sub Command1_Click() Dim rsSql As String OpenDBConnection Set objRs = New ADODB.Recordset rsSql = "Select * FROM myTable" objRs.Open rsSql, objConn, adOpenStatic, adLockReadOnly, adCmdText If Not objRs.EOF Then objRs.MoveLast Debug.Print objRs("name") End If objRs.Close Set objRs = Nothing CloseDBConnection End Sub