jwcolby
jwcolby at colbyconsulting.com
Fri Sep 10 09:02:22 CDT 2010
Yep, another code workaround. I've done this exact thing myself. It does kinda break the "table driven security" model though. Worse, the combo might actually be bound to data in which case selecting that data would modify the form's data since you just toggled the form's AllowEdits to true. Kinda scary! Somewhere way down the road I might look at whether my clsFrmPLSS which loads and implements security for the form could dynamically set this up. It is theoretically possible but I would need a class wrapper to wrap any controls that would need this kind of treatment, and then sink the event in that wrapper and toggle the form's AllowEdits. Each such control type would need it's own wrapper since a class can only sink events if it knows the control type. For a behavior this specific, I could actually write a single generic class which gets passed a control of type control (generic) and then ran a big switch statement to determine what type of control it is and store it to a variable of that control type. Have a ton of dim WithEvent statements in the class header: private mfrm as form private WithEvents cbo as combobox private WithEvents txt as Textbox etc. etc. then: Function mInit(frm as form, Ctl as control) set mfrm = frm select case ctl.type case acTextbox set txt = ctl case acCombobox set cbo = ctl etc etc end select end function Now have event sinks: sub cbo_Gotfocus() mfrm.AllowEdits = True end sub sub cbo_Lostfocus() mfrm.AllowEdits = False end sub This would likely work. Damned ugly though! ;) John W. Colby www.ColbyConsulting.com On 9/10/2010 9:23 AM, Rocky Smolin wrote: > I had this problem on forms which the user may or may not be allowed to edit > based on their access level when they log in at the opening form. > > If they're not allowed edits they still need to select a record from a combo > box. So in the On_Click event of the combo box I set Me.AllowEdits = True, > and then in the Lost Focus of the combo, set AllowEdits = False. > > Rocky