p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

access thread: locking AllForms


Message #1 by "Howard Stone" <ququmber@h...> on Mon, 17 Jun 2002 04:48:27
I have a db that I want to set up so that when it opens all  forms certain 
controls are disabled and locked.

This is the code I attach to the OnLoad event when the Switchboard form 
opens.  I can't get the codes to work because I am missing something I 
cant figure out.

Private Sub Form_Load()
Dim ctl As Control, frm As Form
    
  response = inputBox("Enter code word")   ' code word is password
      
    
For Each frm In Forms
   For Each ctl In Controls
     Select Case ctl.Control
         Case acTextBox, acComboBox, acCheckBox,   
            acCustomControl,acOptionButton
                   If response <> "password" Then
                         With ctl
                             .Locked = True
                             .Enabled = False
                         End With
                   ElseIf response = "password" Then
                         With ctl
                              .Locked = False
                              .Enabled = True
                         End With
                  End If
                                    
            End Select
        Next ctl
    Next frm
 
Message #2 by braxis@b... on Mon, 17 Jun 2002 12:35:50 +0100 (BST)
Howard

Are you receiving an error? Or is it just not doing what you're expecting?

Brian

>  from:    Howard Stone <ququmber@h...>
>  date:    Mon, 17 Jun 2002 05:48:27
>  to:      access@p...
>  subject: Re: [access] locking AllForms
> 
> I have a db that I want to set up so that when it opens all  forms certain 
> controls are disabled and locked.
> 
> This is the code I attach to the OnLoad event when the Switchboard form 
> opens.  I can't get the codes to work because I am missing something I 
> cant figure out.
> 

> Private Sub Form_Load()
> Dim ctl As Control, frm As Form
>     
>   response = inputBox("Enter code word")   ' code word is password
>       
>     
> For Each frm In Forms
>    For Each ctl In Controls
>      Select Case ctl.Control
>          Case acTextBox, acComboBox, acCheckBox,   
>             acCustomControl,acOptionButton
>                    If response <> "password" Then
>                          With ctl
>                              .Locked = True
>                              .Enabled = False
>                          End With
>                    ElseIf response = "password" Then
>                          With ctl
>                               .Locked = False
>                               .Enabled = True
>                          End With
>                   End If
>                                     
>             End Select
>         Next ctl
>     Next frm
>  

Message #3 by "Howard Stone" <ququmber@h...> on Mon, 17 Jun 2002 13:40:43
Thanks for your response ...The program is not doing what it is supposed 
to do.  There is no error message









> I have a db that I want to set up so that when it opens all  forms 
certain 
c> ontrols are disabled and locked.

> This is the code I attach to the OnLoad event when the Switchboard form 
o> pens.  I can't get the codes to work because I am missing something I 
c> ant figure out.

> Private Sub Form_Load()
D> im ctl As Control, frm As Form
 >    
 >  response = inputBox("Enter code word")   ' code word is password
 >      
 >    
F> or Each frm In Forms
 >   For Each ctl In Controls
 >     Select Case ctl.Control
 >         Case acTextBox, acComboBox, acCheckBox,   
 >            acCustomControl,acOptionButton
 >                   If response <> "password" Then
 >                         With ctl
 >                             .Locked = True
 >                             .Enabled = False
 >                         End With
 >                   ElseIf response = "password" Then
 >                         With ctl
 >                              .Locked = False
 >                              .Enabled = True
 >                         End With
 >                  End If
 >                                    
 >            End Select
 >        Next ctl
 >    Next frm
 > 
Message #4 by braxis@b... on Mon, 17 Jun 2002 13:43:32 +0100 (BST)
Howard

Are all your forms open? The Forms collection only holds open forms - so no changes will be made to forms that have not yet been
opened.

Does that help?

Brian

>  from:    Howard Stone <ququmber@h...>
>  date:    Mon, 17 Jun 2002 14:40:43
>  to:      access@p...
>  subject: Re: [access] Re: locking AllForms
> 
> Thanks for your response ...The program is not doing what it is supposed 
> to do.  There is no error message
> 
> 
> 
> 
> 
> 
> 
> 
> 
> > I have a db that I want to set up so that when it opens all  forms 
> certain 
> c> ontrols are disabled and locked.
> 
> > This is the code I attach to the OnLoad event when the Switchboard form 
> o> pens.  I can't get the codes to work because I am missing something I 
> c> ant figure out.
> 
> > Private Sub Form_Load()
> D> im ctl As Control, frm As Form
>  >    
>  >  response = inputBox("Enter code word")   ' code word is password
>  >      
>  >    
> F> or Each frm In Forms
>  >   For Each ctl In Controls
>  >     Select Case ctl.Control
>  >         Case acTextBox, acComboBox, acCheckBox,   
>  >            acCustomControl,acOptionButton
>  >                   If response <> "password" Then
>  >                         With ctl
>  >                             .Locked = True
>  >                             .Enabled = False
>  >                         End With
>  >                   ElseIf response = "password" Then
>  >                         With ctl
>  >                              .Locked = False
>  >                              .Enabled = True
>  >                         End With
>  >                  End If
>  >                                    
>  >            End Select
>  >        Next ctl
>  >    Next frm
>  > 

Message #5 by "Amy Wyatt" <amyw@c...> on Mon, 17 Jun 2002 18:45:26
Try changing this line of code:

Select Case ctl.Control to -> Select Case ctl.ControlType

Amy

> Howard

Are you receiving an error? Or is it just not doing what you're expecting?

Brian

>  from:    Howard Stone <ququmber@h...>
>  date:    Mon, 17 Jun 2002 05:48:27
>  to:      access@p...
>  subject: Re: [access] locking AllForms
> 
> I have a db that I want to set up so that when it opens all  forms 
certain 
> controls are disabled and locked.
> 
> This is the code I attach to the OnLoad event when the Switchboard form 
> opens.  I can't get the codes to work because I am missing something I 
> cant figure out.
> 

> Private Sub Form_Load()
> Dim ctl As Control, frm As Form
>     
>   response = inputBox("Enter code word")   ' code word is password
>       
>     
> For Each frm In Forms
>    For Each ctl In Controls
>      Select Case ctl.Control
>          Case acTextBox, acComboBox, acCheckBox,   
>             acCustomControl,acOptionButton
>                    If response <> "password" Then
>                          With ctl
>                              .Locked = True
>                              .Enabled = False
>                          End With
>                    ElseIf response = "password" Then
>                          With ctl
>                               .Locked = False
>                               .Enabled = True
>                          End With
>                   End If
>                                     
>             End Select
>         Next ctl
>     Next frm
>  


  Return to Index