Solved Test which object on form was clicked (1 Viewer)

Peter Peterson

New member
Local time
Today, 14:38
Joined
Sep 14, 2020
Messages
15
Good morning,
I am using MS Office 365 Pro on the latest version of Windows 10.
I have searched AWF and Google without success - might be my choice of keywords is the issue.
I have used rectangles to track the stage through my process a client is at (see attached image).
The rectangles are unbound.
The "process" is a list in the Clients table.
I have used 'On Click' event to:
1. Change the colour of the old rectangle to light blue and text dark blue (actually, I change all the rectangles to this);
2. Change the colour of the selected rectangle to dark blue and text white and bold;
3. change the 'clientProcess' field in the Clients table to reflect the selected rectangle (i.e. the process);
All of the above works fine, however, I have six "On Click" event procedures, one for each rectangle.
What I want to do is have one procedure called regardless of which rectangle was selected and using a Case Statement update the 'clientProcess' field and rectangle colours depending upon which rectangle was selected.
Is there a way to test which rectangle (or object) was clicked?
In the On Click event (Properties Windows), which reads "[Event Procedure], can I write my own Procedure Name including a value to pass?
If so what is the format?
Thanking you
Peter
 

Attachments

  • Access Form.png
    Access Form.png
    355.3 KB · Views: 21

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:38
Joined
Oct 29, 2018
Messages
13,100
Hi. Maybe one way you could try is to use the MouseUp or MouseDown event.
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 22:38
Joined
May 21, 2018
Messages
3,595
See demo using a single function.
Code:
Private Sub Form_Load()
  SetLight
End Sub
Private Sub SetLight()
  Dim ctrl As Access.Control
  For Each ctrl In Me.Controls
    If ctrl.Tag <> "" Then
      ctrl.BackColor = vbYellow
      ctrl.ForeColor = vbBlack
    End If
  Next ctrl
End Sub
Private Function ClickButton()
  Dim ctrl As Access.Control
  SetLight
  Set ctrl = Me.ActiveControl
  With ctrl
    .BackColor = vbBlue
    .ForeColor = vbWhite
    '.FontWeight = "Bold"
  End With
  MsgBox ctrl.Tag
End Function
 

Attachments

  • ClickedControl.accdb
    404 KB · Views: 15

Peter Peterson

New member
Local time
Today, 14:38
Joined
Sep 14, 2020
Messages
15
Thankyou theDBGuy and pbaldy,
The link provided is interesting reading and may achieve what I need.
I have written a small Procedure "checkSelection"
Code:
Private Sub checkSelection(objectName)
    MsgBox objectname
End Sub
In the Properties Window -> On Click Event - I have typed [QUOTE}Call checkSelection "NumComplete"[QUOTE}
This is obviously incorrect but I have no idea how to call my sub routine.
When I click on the object I get an error message "Microsoft Access cannot find the object 'checkSelection "NumComplete"['
Any guidance will most welcome.
Regards
Peter
 

Peter Peterson

New member
Local time
Today, 14:38
Joined
Sep 14, 2020
Messages
15
Thank you MajP,
I'll read in detail to ensure I learn and understand your solution.
Much appreciated.
Whilst I have got you - I have given you a Thumbs Up, however, I see some threads have a [solved] with them, I don't know how to indicate this thread has been solved.
Thanks again
Peter
 

arnelgp

error reading drive A:
Local time
Today, 11:38
Joined
May 7, 2009
Messages
10,829
activecontrol can only be used on controls that can
have Focus, ie, commandbutton, textbox.
but not rectangles, labels.

another demo.
 

Attachments

  • currentControl.zip
    26.1 KB · Views: 12

Users who are viewing this thread

Top Bottom