datasheet selection on a subform

S

sofakingfree

I posted this in another forum but I thought it would be more
appropriate asked here:

Is there a way to perform actions on the selected records of a
datasheet subform? Actually I know it can be done from a pulldown menu
or a toolbar. But how can you create a button on the form that will do
the same thing? My problem is that every time you select something on
the datasheet when you click a button or any control you will lose the
selection. Is there anyway to prevent that? I'd rather create a
button than try to manage toolbar menus. Any help would be
appreciated. Here is the code that works with menu toolbar:

Public Function t1()
Dim i As Long
Dim strSQL As String
Dim loqd As QueryDef

vbSelectHeight =
Forms!wlef_WorkList_Edit!wlef_WorkList_Edit_Sub.Form.SelHeight

If Forms!wlef_WorkList_Edit!wlef_WorkList_Edit_Sub.Form.SelHeight = 0
Then
Exit Function
End if

With
Forms!wlef_WorkList_Edit!wlef_WorkList_Edit_Sub.Form.RecordsetClone
.MoveFirst
.Move
Forms!wlef_WorkList_Edit!wlef_WorkList_Edit_Sub.Form.SelTop - 1
For i = 1 To vbSelectHeight
MsgBox DocNo 'do something for each selected record
.MoveNext
Next i
End With
End Function
 
G

Guest

If you don;t want to lose selection, keep the left button pressed while
pressing the right one, so as the shortcut menu appears.
If you want to define a button to make a certain action, make a macro and
use runcommand action (it represents all commands in menus, shortcut menus
and toolbars in access)

Hope this works.
 
D

Dirk Goldgar

I posted this in another forum but I thought it would be more
appropriate asked here:

Is there a way to perform actions on the selected records of a
datasheet subform? Actually I know it can be done from a pulldown
menu or a toolbar. But how can you create a button on the form that
will do the same thing? My problem is that every time you select
something on the datasheet when you click a button or any control you
will lose the selection. Is there anyway to prevent that? I'd
rather create a button than try to manage toolbar menus. Any help
would be appreciated. Here is the code that works with menu toolbar:

Public Function t1()
Dim i As Long
Dim strSQL As String
Dim loqd As QueryDef

vbSelectHeight =
Forms!wlef_WorkList_Edit!wlef_WorkList_Edit_Sub.Form.SelHeight

If Forms!wlef_WorkList_Edit!wlef_WorkList_Edit_Sub.Form.SelHeight = 0
Then
Exit Function
End if

With
Forms!wlef_WorkList_Edit!wlef_WorkList_Edit_Sub.Form.RecordsetClone
.MoveFirst
.Move
Forms!wlef_WorkList_Edit!wlef_WorkList_Edit_Sub.Form.SelTop - 1
For i = 1 To vbSelectHeight
MsgBox DocNo 'do something for each selected record
.MoveNext
Next i
End With
End Function

On solution is to record the form's values for SelTop and SelHeight in
public variables in the form's module, during the form's Click event.
Note that I'm talking here about the subform's Source Object form and
its module, not the main form that is hosting the subform control.
Anyway, the code in the subform form's module could look like this:

'----- start of exampole code for form module -----
Option Compare Database
Option Explicit

Public lngSelTop As Long
Public lngSelHeight As Long

Private Sub Form_Click()

lngSelTop = Me.SelTop
lngSelHeight = Me.SelHeight

End Sub
'----- end of exampole code for form module -----

Then your code for the command button on the main form could refer to
the values captured and made public on the subform:

vbSelectHeight = Me!wlef_WorkList_Edit_Sub.Form.lngSelHeight

' ...

.Move Me!wlef_WorkList_Edit_Sub.Form.lngSelTop - 1

' ...

and so on.
 

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