473,406 Members | 2,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Single Handler for the Click Event in Multiple Controls of a Form

There are some combobox in my form .
When the user clicks on any of them while the AllowEdits property is seting to false , I want to note him that it is'nt avilble to edit the data.
I think should use the technique of class but as new in VBA cuold not find
Sorry for my poor English and Thanks in advance
Mar 15 '16 #1
4 2198
NeoPa
32,556 Expert Mod 16PB
I suspect you could define a class based on the ComboBox control.

Beware, events only get passed on to the handler in the class if the object handled by the class already has a handler for that event.

As an example, here's a fairly basic class module that I've used for handling hierarchical opening and closing of forms :
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. '21/1/2004  Added Private Set & Public Get code for frmTo.
  5. '21/9/2004  Removed ResumeTo functionality. _
  6.             Now handled by the OnTimer() subroutine in the calling form _
  7.             checking for (Visible) which indicates the called form is finished.
  8. '24/2/2005  Added function Uninitialised to show if instance of this object _
  9.             has yet been initialised with the callers info. _
  10.             It also checks this before it tries to open a new form.
  11. '31/3/2008  Added varOpenArgs as optional parameter to ShowForm.  Simply to be _
  12.             passed directly to the opened form using DoCmd.OpenForm(). _
  13.             Also set .OpenForm() to treat Cancel of the open as NOT an error.
  14.  
  15. Private Const conUnInitMsg As String = _
  16.                   "Object uninitialised - unable to show form."
  17.  
  18. Private frmParent As Form
  19. Private WithEvents frmCalled As Form
  20.  
  21. Public Property Set frmFrom(frmValue As Form)
  22.     Set frmParent = frmValue
  23. End Property
  24.  
  25. Private Property Get frmFrom() As Form
  26.     Set frmFrom = frmParent
  27. End Property
  28.  
  29. Private Property Set frmTo(frmValue As Form)
  30.     Set frmCalled = frmValue
  31. End Property
  32.  
  33. Public Property Get frmTo() As Form
  34.     Set frmTo = frmCalled
  35. End Property
  36.  
  37. 'Uninitialised returns True if frmFrom not yet initialised.
  38. Public Function Uninitialised() As Boolean
  39.     Uninitialised = (frmParent Is Nothing)
  40. End Function
  41.  
  42. 'ShowForm opens form strTo and hides the calling form.  Returns True on success.
  43. Public Function ShowForm(strTo As String, _
  44.                          Optional strFilter As String = "", _
  45.                          Optional varOpenArgs As Variant = Null) As Boolean
  46.     ShowForm = True
  47.     'Don't even try if caller hasn't initialised Form object yet
  48.     If Uninitialised() Then
  49.         ShowForm = False
  50.         Call ShowMsg(strMsg:=conUnInitMsg, strTitle:="classForm.ShowForm")
  51.         Exit Function
  52.     End If
  53.     Call DoCmd.Restore
  54.     'Handle error on OpenForm() only.
  55.     On Error GoTo ErrorSF
  56.     Call DoCmd.OpenForm(FormName:=strTo, _
  57.                         WhereCondition:=strFilter, _
  58.                         OpenArgs:=varOpenArgs)
  59.     On Error GoTo 0
  60.     Set frmTo = Forms(strTo)
  61.     frmFrom.Visible = False
  62.     Exit Function
  63.  
  64. ErrorSF:
  65.     ShowForm = False
  66.     ' If open is cancelled (either by user or code) then simply exit
  67.     If Err.Number <> 2501 Then _
  68.         Call ErrorHandler(strName:=strTo, _
  69.                           strFrom:=frmFrom.Name & ".ShowForm", _
  70.                           lngErrNo:=Err.Number, _
  71.                           strDesc:=Err.Description)
  72. End Function
  73.  
  74. '************************* Contained Object Method(s) *************************
  75. 'For these subroutines to be activated the contained object must have the
  76. ''On Close' property set to a valid subroutine within the contained object.
  77. Private Sub frmCalled_Close()
  78.     frmFrom.Visible = True
  79.     Call DoCmd.Restore
  80.     Set frmTo = Nothing
  81. End Sub
  82. '******************************************************************************
Mar 15 '16 #2
Thank you NeoPa ,for your quick response.
At this point, I can not delve into the issue because of its important ingredients change.
When I get to be able to return to the subject later - my response will be more specific.
Thank You .
Mar 17 '16 #3
calaxan
12
What i get from Yoel Duady question is to prevent the User modify/change value in the combobox. If it's so, why don't you use LimitToList property.
Set LimitToList in the combobox properties to YES.

Sorry if it's not giving you a solution.
Mar 17 '16 #4
NeoPa
32,556 Expert Mod 16PB
That's not a correct understanding Calaxan. What they want is to update any and all controls on a form that have been changed, IE. The value is different from the saved data. Essentially, something that reflects dirtied controls. Ones that have been updated will have one background colour, while those that haven't will have another.

@Yoel.
That's fine. Come back when you're ready. We'll still be here :-)
Mar 17 '16 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: William Wisnieski | last post by:
Hello Everyone, Access 2000 I have a form with multiple pages on it. There is one text field on the third page of the form that I need the user to complete before leaving the form or moving...
2
by: Keith Smith | last post by:
Is there a way to attach event handler code to multiple controls?
3
by: TT (Tom Tempelaere) | last post by:
Hi there, In my application I have a panel that contains a matrix of user controls. The user control is fairly simple. It merely draws a circle that represents an object in my code. The object...
3
by: R Millman | last post by:
under ASP.NET, single stepping in debug mode appears not to stop within event procedures. i.e. 1) Create web page with submit button and event procedure for the click event in the code behind...
3
by: Nathan Sokalski | last post by:
When I view any page in my application a second time, I recieve the following error: System.Web.TraceContext.AddNewControl(String id, String parentId, String type, Int32 viewStateSize) +313...
4
by: Rich | last post by:
Hello, I create multiple pictureboxe controls on a form in a For Loop and display thumbnail pictures. I need to add a Click event to these pictureboxes. Here is the routine that creates the...
6
by: Willem | last post by:
I have got a very simple javascript which compares about 8 controls in pairs of two. i.e. maxA - minA <= 25. Now I would like it to be triggered for validation (before submit?) and cancel the...
2
by: jpr | last post by:
Hello, I have a form with multiple controls (textboxes) named: Father Mother Child1 Child2 On the form there are also two checkboxes (check1 and check2).
8
by: hoofbeats95 | last post by:
I don't think this should be this complicated, but I can't figure it out. I've worked with C# for several years now, but in a web environment, not with windows form. I have a form with a query...
0
by: Neil | last post by:
Here's a follow-up to my "Concatenating Rich Textbox Controls Into A Single File" message. I didn't get any useful responses to that message, so I assume that there isn't a direct way to create a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.