HowTo get the current record

  • Thread starter Thread starter Harry
  • Start date Start date
H

Harry

Hi

I have a sub-form which displays a recordset of search
results. The user is then to select one record and click
on a command button to perform an action on that record,
however I do not know how to identify the selected record
and then extract the records data!?

Thanks

Harry
 
Harry said:
I have a sub-form which displays a recordset of search
results. The user is then to select one record and click
on a command button to perform an action on that record,
however I do not know how to identify the selected record
and then extract the records data!?

Access forms have an On Current Event which occurs when a record gets focus.
As soon as the user selects a record with the mouse or keyboard this event
fires. You can use the event to read data from any control (textbox,
combobox, etc.) on the selected record.

One thing you may need to watch out for is a user who is scrolling through
records. As each gets focus the Current event fires.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
Arvin

Thanks for the response. I would like to find a different
way to do it so as to avoid the event firing each time the
user clicks on a record. What do you think about using
the CurrentRecord command which gives the selected record
number? But I dont know how to associate the record
number with the text box that contains the primary key in
that record?

Thanks

Harry
 
I think your problem is more "When" than "How".

You might try using a timer delay for a few seconds so that the code won't
run immediately after a click on a record. You don't say what type of
subform, but if it were a continuous type, you could have a button in the
header, or footer, or even on each row which will run the code on the click
event. The value you are looking for is simply stored in the current
record's control. For instance, you can refer to the ID (Primary Key) of the
record by several methods: (Let's assume that the ID is in a textbox named
txtID)

Me.txtID.Value
Me.txt.ID
Me("txtID")
Forms!FormName!txtID.Value
Forms!FormName!txtID

Say you wanted to run a report for that record:

DoCmd.OpenReport "ReportName",,,"ID =" & Me.txtID
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
Back
Top