How to make a row selectable in a table (1 Viewer)

silversun

Registered User.
Local time
Today, 05:20
Joined
Dec 28, 2012
Messages
204
Hi everybody,
I have a subform based on a select query. I need to store the content of one of the controls in selected row (an ID) for later use. Users usually hover on the rows then select or click on one of them. I don't know how I can make my table rows selectable like that. Is there someone who can help me on that?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:20
Joined
Oct 29, 2018
Messages
21,358
Hi. Not sure I follow. Are you able to post some images demonstrating what you mean? Thanks.
 

silversun

Registered User.
Local time
Today, 05:20
Joined
Dec 28, 2012
Messages
204
@ theDBguy
Sure, Here is the image attached.
When user selects Patrick from customers combo box then all cars belong to Patrick are displayed in subform as you can see in the image.
Now user clicks on one of them, for example Mazda MX-5 is selected by user then subform sends the value of carOwner_ID to a variable in the VBA module so that I can store it later on in tbl_services. The value in this example is 12. To make it more user friendly I prefer to have a row highlighted when user hovers on them.
I hope you got the idea. My English is not very well but I am trying my best to deliver my idea as simplest as I can.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:20
Joined
Oct 29, 2018
Messages
21,358
To make it more user friendly I prefer to have a row highlighted when user hovers on them.
Hi. Thanks for the additional information. You can highlight a row when the user clicks on it, but doing it during a mouse hover is a little tricky.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:20
Joined
Aug 30, 2003
Messages
36,118
In the current event of the subform you can have:

VariableName = Me.carOwner_ID

presuming the variable is declared as public in a standard module, any time a record is selected the variable will be populated with the ID and be available for use elsewhere.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 05:20
Joined
Oct 29, 2018
Messages
21,358
In the current event of the subform you can have:

VariableName = Me.carOwner_ID

presuming the variable is declared as public in a standard module, any time a record is selected the variable will be populated with the ID and be available for use elsewhere.
Hi silversun. I agree with Paul. But again, the current event and the record being selected means the user has to "click" on it. Hovering doesn't select a record, if that's what you were asking.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:20
Joined
Aug 30, 2003
Messages
36,118
I may have misread. I thought there were two different requests with the hover option as the ideal. Now that I reread it sounds like it's already working with the click, so sorry for jumping in.
 

isladogs

MVP / VIP
Local time
Today, 12:20
Joined
Jan 14, 2017
Messages
18,186
It is possible to 'select' a record using mouse move but it involves some complex code to determine the position of the mouse cursor on screen and the contents of the form in exactly the same position.
See this link for an example using listboxes Accurately Move Forms and Controls.

Whether its worth the effort involved in doing this is another matter
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 08:20
Joined
May 21, 2018
Messages
8,463
As stated the hover requires a lot of code, but the click is very simple to highlight a row. If the click suffices then.
code in subform
Code:
Private Sub Form_Current()
  Me.Tag = Nz(Me.carID)
  Me.Refresh
End Sub

Private Function IsSelected()
  IsSelected = (Nz(Me.carID) = Me.Tag)
End Function

Then using conditional format
Expression: IsSelected()



 

Attachments

  • Conditional.jpg
    Conditional.jpg
    56 KB · Views: 226
  • SelectedRow.jpg
    SelectedRow.jpg
    21.7 KB · Views: 219

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 20:20
Joined
May 7, 2009
Messages
19,175
you could just add an unbound textbox and on current set it to the current record's ID.

cf [ID]=[txtUnbound]

no need for additional code and tag.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 08:20
Joined
May 21, 2018
Messages
8,463
Code:
no need for additional code and tag
Or simply paste my solution and no need for an unnecessary unbound control. However, the additional two lines of code could be extremely problematic (insert sarcasm emoji).
 

Users who are viewing this thread

Top Bottom