We help IT Professionals succeed at work.

msaccess event associated with row selection for data sheet

hi dudes and dudets,

I have a form with a data sheet on it.

Is there an event associated with the selection of a record (row) for the data sheet?

    (You can select a row (click on the left) without selection a field.)

Is there a way to know the record "number" of the record selected?


Thanks,

Cg
Comment
Watch Question

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007

Commented:
"Is there an event associated with the selection of a record (row) for the data sheet?"

IF ... you click on the Form Record Selector on the far left ... the the Form Click event will occur.

IF ... you click anywhere in the row in a control ... the Form On Current event will occur

mx
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007

Commented:
Actually ...

IF ... you click on the Form Record Selector on the far left ... the the Form Click and Form On Current events will occur.

mx
Database Architect / Application Developer
Top Expert 2007
Commented:
This will give you the current record number:

    Dim x
    x = Me.CurrentRecord
    MsgBox x

mx
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007

Commented:
Also ... I think it's dudette :-)

mx
Scott McDaniel (EE MVE )Infotrakker Software
Most Valuable Expert 2012
Top Expert 2014

Commented:
Just my .02: But ANYTIME you change to a different record, the Current event will fire and is the event that should be used if you need to fire code anytime the user moves to a different record. The Click even won't fire if you Tab or PageUp/PageDown into records.
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007

Commented:
Well, but .... the Q was (in part):

"Is there an event associated with the selection of a record (row) for the data sheet?"

And the Form Click event does fire when you hit the record selector.  In fact, there is only one other place - which I can't remember right now - that the Form Click event occurs.

mx
Scott McDaniel (EE MVE )Infotrakker Software
Most Valuable Expert 2012
Top Expert 2014

Commented:
We'd have to have a definition of "selection" before you could insure that the Click event is a valid choice. In more than a few cases users in Datasheet view never touch the mouse, thus the Click event would never fire. The Current event always fires when you change records, whether you use the keyboard or mouse.

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Application Developer
Top Expert 2007

Commented:
I'm not disagreeing ... and I did mention the Click event occurs also :-)

mx