Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count of Selected Controls

Status
Not open for further replies.

ShaimaaT

Programmer
Aug 18, 2014
16
EG
Hi all,

I have a form consisting of textboxes and I open it in datasheet view.

I want to be able to ctrl+v something if I am selecting only one control(one textbox).

But if several texboxes are selected , or the whole record ...then I want to pop up a user-friendly message and disable pasting.

I am thinking of something like

Dim Pasted As Boolean
Dim ctrl As Control

Private Sub Form_BeforeInsert(Cancel As Integer)
If (ctrl.ItemsSelected.Count > 1) Then [highlight #3465A4]<--- this seems to be wrong /missing[/highlight]
Cancel = Pasted
If (Cancel = True) Then
MsgBox "Please paste one field at a time"
End If
End If

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

Pasted = KeyCode = vbKeyV And Shift = acCtrlMask

End Sub
 
I believe you can get the number of selected columns and rows using the properties
me.selWidth (>0 is more than one column)
me.selHeight (>0 is more than one column)

I think your issue is going to be trapping the events. I am not sure if a proper event exists to do this, without playing with it.
 
me.selwidth is zero when I select a whole record.
 
Seems to be over complicated. All the user can do is copy a value from a single control, so focus on that. I would either add events at the control level (like a double click) to copy the active control value, or put the datasheet as a subform. On the main form I would add features to copy and paste and control the datasheet.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top