Switch from datasheet to form view - select first record

G

GG

Hi, all,

I have a simple bound form that can be switched between datasheet and
form views through a toolbar button (no problem). What I want is when
multiple records have been selected in datasheet view, and the user
switches to form view, only the first record is selected. This would
prevent the user from deletting all the selected records -when only the
first can be seen in form view- when clicking a button in the toolbar
set to a function to delete records. The user should be able to select
and delete multiple records only in datasheet view.

Thank you for any suggestion.
GG
 
G

Gaby

I think I wasn't clear enough... The question would be: in datasheet
view when multiple records are selected (highlighted), how do I change
or clear that selection to select only the first record (current). In
other words, how do I make Me.SelHeight=1.

I've found the solution with DoCmd.RunCommand acCmdSelectRecord.
However, I discovered something strange... If this command is run
within a function called from a toolbar button, it only works if the
form is in datasheet view (you can see it); if the form is in form
view, it just do nothing, no error message (and you can't notice it
because only one record is shown when actually more than one may be
selected). But if it is called from a button in the form (in form view
only, of course), it works. Below is the code I used to show this
behavior:

'Function called in toolbar button
Public Function SelectFirst() As Boolean
DoCmd.RunCommand acCmdSelectRecord
MsgBox Me.SelHeight
End Function

'Button in form.
Private Sub btnSelectFirst_Click()
Dim b As Boolean
b = SelectFirst()
End Sub

In my application context, the sequence of commands when switching from
datasheet to form view with a toolbar button has to be:

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdFormView

I post this solution just in case someone else runs into this problem.

Thank you anyway for reading,

Gaby (GG)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top