Get Selected Record In Activedatasheet [solved]
I am trying to get a value from an ActiveDatasheet. The following code returns the correct record number but the data is from record 1 (or another record in the middle of the table when using other dbOpen.. arguments. Any help appreciated.
I am trying to get a value from an ActiveDatasheet. The following code returns the correct record number but the data is from record 1 (or another record in the middle of the table when using other dbOpen.. arguments. Any help appreciated.
Code:
Dim rst As Recordset
Dim recno As Long
Dim Proj As String
'------------------
Set rst = CurrentDb.OpenRecordset("YP17", dbOpenDynaset)
recno = Screen.ActiveDatasheet.CurrentRecord
'---------------------------------------------
'- version 1
'rst.Move 0
'---------------------------------------------
'- version 2
rst.MoveLast
rst.MoveFirst
rst.Move recno
'---------------------------------------------
Proj = rst.Fields("Project Number")
MsgBox ("CurrentRecord = " & recno & vbCr & Proj)
rst.Close
End Sub
Last edited: