Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable double click event on a form using VBA

Status
Not open for further replies.

DomFino

IS-IT--Management
Jul 9, 2003
278
US
Hi all,

I have a database with security that allows four levels of access, (e.g.,Admin, Power User, Project Manager, and Guest) which are associated with a value (AccessID) of 1, 2, 3, and 4 respectively.

The security seems to work fine except on a form that uses a call function on the double click event of a txtcontrol to pop up a calender to select a date.

I was wondering if there is a way to turn the call statement off via code. In this case if the User.AccessID = 4 do not allow the call to occur.

For example if the security level is read only (4) then either the double click event should be turned off somehow or the call function should not fire. I suspect I would have to put code on each control that pops up the calender,
Me.ProjectStartDate
Me.ProjectEndDate, etc.

Here is a sample of the on open code I am using.

Code:
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open

If User.AccessID = 1 Or User.AccessID = 2 Then
    'Here list all buttons and controls that should be enabled for level 1 and 2
        Me.AllowEdits = True
        Me.AllowAdditions = True
        Me.AllowDeletions = True
    Else
    
    'Here list all buttons and controls that should be enabled for level 3 only
    If User.AccessID = 3 Then
        Me.AllowEdits = False
        Me.AllowAdditions = True
        Me.AllowDeletions = False
    Else
    
    'Here list all buttons and controls that should be enabled for level 4 only
    If User.AccessID = 4 Then
        Me.AllowEdits = False
        Me.AllowAdditions = False
        Me.AllowDeletions = False
    End If
End If
End If
    
Exit_Form_Open:
    Exit Sub

Err_Form_Open:
    MsgBox Err.Description
    Me.Visible = True
    Resume Exit_Form_Open
          
End Sub
 
Couldn't you put similar code in the Form_DblClick sub? This way, whenever the form is Dblclicked, it will run your code instead of doing just whatever it wants.

Also, I would suggest a CASE statement rather than IF-THEN; it may make things eaiser to understand.

Select Case User.AccessID

Case 1 or 2

Me.AllowEdits = True
Me.AllowAdditions = True
Me.AllowDeletions = True

Case 3

...

Case 4

...

End Select

Hope this helps...

LF


"As far as the laws of mathematics refer to reality, they are not certain; as far as they are certain, they do not refer to reality."--Albert Einstein
 
Homersim2600,
Thanks for your reply.

I tried putting this code on the forms double click event as a quick test.

Code:
Private Sub Form_DblClick(Cancel As Integer)
    If User.AccessID = 4 Then
        Me.AllowEdits = False
        Me.AllowAdditions = False
        Me.AllowDeletions = False
    End If

End Sub

What happens is the user logged in with AccessID = 4 is permitted to make changes but the record will not save, Once the user pressed escape, the original values are restored and the user can go to another form, etc., which is a good thing. I guess I was looking for a way to not allow the user to enter any data at all. Basically locking all the fields on the form.

By the way, I like your idea of using Case. I will play with that later today.
Thanks
Dom
 
The answer to your question is YES! Yeaaaahhh! :) Sorry for the excitement, I just found out that i am off tomorrow!

Ok, add this line to your code...

I am using datagrid as an example, but you can change that to your needs. I think just about every control has a enabled property.

Datagrid1.enabled = False
or
Text1.enabled = false
or
Form1.enabled = false, hehe

This will allow the user to read the contents of this, but not allow them to do anything. I hope this helps...

LF


"As far as the laws of mathematics refer to reality, they are not certain; as far as they are certain, they do not refer to reality."--Albert Einstein
 
Thank, I will give that a go.

Enjoy your day off!
Dom
 
Hi all,
I am trying to use the Case statement below to validate security on certain forms. The security seems to work fine except when one user logs off and another logs on with a different security level. I receive the following error:

Could not update; currently locked by another session on this machine. (Error 3188)

Is there some way to free up the previous security level so that on open the new security level is effective? I must be missing something.

Thanks for your help.
Dom

Code:
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open

Select Case User.AccessID

    Case 1

    'Here list all buttons and controls that should be enabled for level 1
        Me.AllowEdits = True
        Me.AllowAdditions = True
        Me.AllowDeletions = True
        Me.sfmGrant.Enabled = True
        Me.sfmContactsBaseData.Enabled = True
        Me.sfmContactsHistory.Enabled = True
        Me.sfmApprovedBudget.Enabled = True
        Me.sfmTickler.Enabled = True
        Me.fsubAttachments.Enabled = True
        Me.sfmFunding.Enabled = True
        
    Case 2

    'Here list all buttons and controls that should be enabled for level 2
        Me.AllowEdits = True
        Me.AllowAdditions = True
        Me.AllowDeletions = True
        Me.sfmGrant.Enabled = True
        Me.sfmContactsBaseData.Enabled = True
        Me.sfmContactsHistory.Enabled = True
        Me.sfmApprovedBudget.Enabled = True
        Me.sfmTickler.Enabled = True
        Me.fsubAttachments.Enabled = True
        Me.sfmFunding.Enabled = True
        
    Case 3
    
    'Here list all buttons and controls that should be enabled for level 3 only
   ' If User.AccessID = 3 Then
        Me.AllowEdits = False
        Me.AllowAdditions = True
        Me.AllowDeletions = False
        Me.sfmGrant.Enabled = False
        Me.sfmContactsBaseData.Enabled = True
        Me.sfmContactsHistory.Enabled = False
        Me.sfmApprovedBudget.Enabled = False
        Me.sfmTickler.Enabled = False
        Me.fsubAttachments.Enabled = False
        Me.sfmFunding.Enabled = False
        
    Case 4
    
    'Here list all buttons and controls that should be enabled for level 4 only
   ' If User.AccessID = 4 Then
        Me.AllowEdits = False
        Me.AllowAdditions = False
        Me.AllowDeletions = False
        Me.sfmGrant.Enabled = False
        Me.sfmContactsBaseData.Enabled = False
        Me.sfmContactsHistory.Enabled = False
        Me.sfmApprovedBudget.Enabled = False
        Me.sfmTickler.Enabled = False
        Me.fsubAttachments.Enabled = False
        Me.sfmFunding.Enabled = False
        
    End Select
    
Exit_Form_Open:
    Exit Sub

Err_Form_Open:
    MsgBox Err.Description
    Me.Visible = True
    Resume Exit_Form_Open
          
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top