I am trying to use ActiveDatasheet in VBA code to access the default form that comes from doubleclicking a table name. The code to run from a button will eventually open a text file that acted as the imported data source - the filename is in one of the fields.
The problem is that my code correctly gets the record number from the data form, but returns the field contents of some other record - not the selected one. I do not really want to set up a special form to do this because it means that it will have to be running already.
The code contains 2 methods that I have tried. This one always refers to the field in record 1. The other one goes to some other record.
Any help appreciated. eg. Is there another way I can get the record contents from the record number ?
Code:
Option Compare Database
Option Explicit
Function get_file()
Dim rst As Recordset
Dim recno As Long
Dim Proj As String
'------------------
Set rst = CurrentDb.OpenRecordset("CSV_LOG")
recno = Screen.ActiveDatasheet.CurrentRecord
'---------------------------------------------
'- version 1
rst.Move 0
'---------------------------------------------
'- version 2
'rst.MoveLast
'rst.MoveFirst
'rst.Move recno
'---------------------------------------------
Proj = rst.Fields("CSV_file")
MsgBox ("CurrentRecord = " & recno & vbCr & Proj)
rst.Close
End Function
-----------------------
Regards BrianB
Most problems occur from starting at the wrong place.
Use a cup of coffee to make Windows run faster.
It is easy until you know how.