From: alekm on 14 May 2010 08:36 Hi, here is my code event procedure for a check box. I want to allow some users to change its state and to prevent otheres from change it. Is there any way I can ban that SendKeys "{ESC}" line? That line is the only way it works not ending in the loop (you press anything on the form, msgbox pops up again), but I don't see why?? Private Sub MyCheckBox_BeforeUpdate(Cancel As Integer) If currentuser <> "RightUser" Then MsgBox ("You are not right user. You don't touch this check box.") Cancel = True SendKeys "{ESC}" ' without last line msgbox pops up again and again when you press ' anything on the form ' only escape key stops it. Why?! End If End Sub Any solutions? Thanx alekmil
From: BruceM via AccessMonster.com on 14 May 2010 09:15 Rather than scolding the user for checking a box they may have checked in good faith, either disable or hide the box. You don't say how you are identifying the "RightUser", but if you are using User Level Security (ULS) you can use the form's Open event: Me.CheckBoxName.Enabled = (CurrentUser = "RightUser") or Me.CheckBoxName.Visible = (CurrentUser = "RightUser") If you are not using ULS, CurrentUser is Admin, and nobody will see an enabled check box. If you are using ULS, you may want to use groups rather than individual users. For instance, everybody who can check the box is in the Managers group. Place something like the following in a standard module: Public Function UserGroup(ByVal GroupName As String) As Boolean On Error GoTo UserGroup_Error Dim usr As DAO.User Dim grp As DAO.Group Set usr = DBEngine.Workspaces(0).Users(CurrentUser) For Each grp In usr.Groups If grp.Name = GroupName Then UserGroup = True Exit For End If Next grp ProcExit: Exit Function UserGroup_Error: MsgBox "Error " & Err.Number & " (" & Err.Description & ") " & _ "in UserGroup, Form_frmCAR" Resume ProcExit End Function I would give credit for the code if I could remember where it came from, but I don't seem to have noted that. Anyhow, in the form's Open event you could have: Me.CheckBoxName.Enabled = UserGroup("Managers") Note that ULS is for Access 2003 and earlier, or later versions that use the 2003 format. alekm wrote: >Hi, >here is my code event procedure for a check box. I want to allow some users >to change its state and to prevent otheres from change it. Is there any way I >can ban that SendKeys "{ESC}" line? That line is the only way it works not >ending in the loop (you press anything on the form, msgbox pops up again), >but I don't see why?? > >Private Sub MyCheckBox_BeforeUpdate(Cancel As Integer) > >If currentuser <> "RightUser" Then > > MsgBox ("You are not right user. You don't touch this check box.") > Cancel = True > SendKeys "{ESC}" > ' without last line msgbox pops up again and again when you press > ' anything on the form > ' only escape key stops it. Why?! > >End If > >End Sub > >Any solutions? >Thanx > >alekmil -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/201005/1
From: Krzysztof Naworyta on 14 May 2010 11:08 Juzer alekm <alekm(a)discussions.microsoft.com> napisa� | here is my code event procedure for a check box. I want to allow some | users to change its state and to prevent otheres from change it. Is | there any way I can ban that SendKeys "{ESC}" line? That line is the | only way it works not ending in the loop (you press anything on the | form, msgbox pops up again), but I don't see why?? | | | Private Sub MyCheckBox_BeforeUpdate(Cancel As Integer) | | If currentuser <> "RightUser" Then | | MsgBox ("You are not right user. You don't touch this check | box.") Cancel = True | SendKeys "{ESC}" | ' without last line msgbox pops up again and again when you | press ' anything on the form | ' only escape key stops it. Why?! | | End If | | End Sub In fact a checkbox (as an option button and a toggle butoon) has not BeforeUpdate event. This event triggers in the same moment as AfterUpdate (and OnClick) and can not be canceled. You can use AfterUpdate event intead, changing wrong value: Private Sub MyCheckBox_AfterUpdate() If currentuser <> "RightUser" Then MsgBox "Bla bla..." With MyCheckBox if .Value = True then .Value = False end if 'or: '.Value = Not .Value End If End Sub -- KN archiwum grupy: http://groups.google.pl/advanced_search (grupa: pl*msaccess)
From: BruceM via AccessMonster.com on 14 May 2010 11:35 A check box as an option group control does not have Before Update, but a single check box bound to a table field does. If you use the After Update event as you have shown the value will be updated, and the After Update code will run again, which means the value will be updated, and the After Update code will run again.... The user will be able to do nothing but click the message box button over and over. Krzysztof Naworyta wrote: >Juzer alekm <alekm(a)discussions.microsoft.com> napisał > >| here is my code event procedure for a check box. I want to allow some >| users to change its state and to prevent otheres from change it. Is >[quoted text clipped - 16 lines] >| >| End Sub > >In fact a checkbox (as an option button and a toggle butoon) has not >BeforeUpdate event. >This event triggers in the same moment as AfterUpdate (and OnClick) and >can not be canceled. > >You can use AfterUpdate event intead, changing wrong value: > >Private Sub MyCheckBox_AfterUpdate() > > If currentuser <> "RightUser" Then > MsgBox "Bla bla..." > With MyCheckBox > if .Value = True then > .Value = False > end if > 'or: > '.Value = Not .Value > End If > >End Sub > -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/201005/1
From: Dirk Goldgar on 14 May 2010 11:44 "alekm" <alekm(a)discussions.microsoft.com> wrote in message news:48086958-16B3-4A58-B4F5-DCDE2F96C02A(a)microsoft.com... > Hi, > here is my code event procedure for a check box. I want to allow some > users > to change its state and to prevent otheres from change it. Is there any > way I > can ban that SendKeys "{ESC}" line? That line is the only way it works > not > ending in the loop (you press anything on the form, msgbox pops up again), > but I don't see why?? > > > Private Sub MyCheckBox_BeforeUpdate(Cancel As Integer) > > If currentuser <> "RightUser" Then > > MsgBox ("You are not right user. You don't touch this check box.") > Cancel = True > SendKeys "{ESC}" > ' without last line msgbox pops up again and again when you press > ' anything on the form > ' only escape key stops it. Why?! > > End If > > End Sub You don't need SendKeys, you can use Me.MyCheckBox.Undo instead. You need to undo the change to the checkbox because, although setting Cancel=True disallows the update, the user's change to the checkbox value is still pending, and Access will keep attempting to reapply it until you undo it, whether by the .Undo method or by pressing/sending the Escape key. -- Dirk Goldgar, MS Access MVP Access tips: www.datagnostics.com/tips.html (please reply to the newsgroup)
|
Next
|
Last
Pages: 1 2 3 Prev: How do I check the current value of check box not reffering it Next: Email problem |