[AccessD] Locking form controls 2003

Kath Pelletti kp at sdsonline.net
Wed Feb 13 17:03:34 CST 2008


Jim - thanks. Using the tag property is a great idea......

Kath
----- Original Message ----- 
From: "Jim Dettman" <jimdettman at verizon.net>
To: "'Access Developers discussion and problem solving'" 
<accessd at databaseadvisors.com>
Sent: Thursday, February 14, 2008 1:25 AM
Subject: Re: [AccessD] Locking form controls 2003


>  FWIW, see the code below.  Besides checking for the section, you might
> also want to put a tag in the tag property of each control as to whether 
> or
> not it should be locked.  What you'll find on many forms is that some
> controls need to remain unlocked.  In my case, my standard form handler 
> had
> a control panel in the form header, which is why I did controls only in 
> the
> detail section.
>
>  And as John said, you need to have focus on another control before you 
> can
> disable or lock a control.
>
>  Note that the code below needs some cleanup (it's from my A2 days; what
> can I say<g>).  The object variables should be set to nothing, etc., but 
> it
> does work.
>
> Jim.
>
> Function StdLockForm(frm As Form, intState As Integer)
>
>  'Lock/unlock all the fields in the detail section of the form that are
> enabled.
>
>  Dim intL As Integer              'Generic loop counter
>  Dim intCount As Integer          'Number of controls on the form
>
>  intCount = frm.Count             'Find out how many controls are on the
> form
>
>  On Error Resume Next
>  For intL = 0 To intCount - 1      'Step thru all controls on the form
>    If (frm(intL).Section = False) Then 'Don't do any control execpt those
> in the detail section
>        If (frm(intL).Enabled = True) Then frm(intL).Locked = intState
> 'Set 'Locked' property to proper state
>    End If
>  Next intL
>  On Error GoTo 0
>
> End Function
>
> Call examples:
>
> Function LockForm(FormName As String)
>
>  Dim frm As Form
>
>  Set frm = Forms(FormName)
>  LockForm = StdLockForm(frm, True)
>
> End Function
>
> Function UnLockForm(FormName As String)
>
>  Dim frm As Form
>
>  Set frm = Forms(FormName)
>  UnLockForm = StdLockForm(frm, False)
>
> End Function
>
> -----Original Message-----
> From: accessd-bounces at databaseadvisors.com
> [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Kath Pelletti
> Sent: Tuesday, February 12, 2008 10:56 PM
> To: Access D Normal List
> Subject: [AccessD] Locking form controls 2003
>
> Help please gurus.......trying to develop a routine which will lock (or
> disable) controls on a form. (Access 2003)
>
> I am getting error 438 'Object doesn't support this property or method' on
> the line 'Select Case ctl.type'.
>
> Any idea why? I am using code I have used in 2000. Can I no longer say
> ctl.type?
>
> See code below:
>
> ----------------------------------------------------------------------------
> ----
>
>
> Code :
>
> Public Function LockControls(strformname As String)
> Dim frmIn As Form
> Dim strerrormsg As String
> Dim ctl As Control
> 'On Error GoTo Err_Handler
>
> Set frmIn = Forms(strformname)
>    For Each ctl In frmIn.Controls
>             Select Case ctl.Type                                    'error
> occurs on this line............
>                 Case acTextBox: ctl.Locked = True
>             End Select
>    Next
>
> Normal_exit:
>    DoCmd.SetWarnings True
>    Exit Function
>
> Err_Handler:
>    MsgBox "Error: [" & Err.Number & "]  " & IIf(Len(strerrormsg) > 0,
> strerrormsg, Err.Description), vbCritical, "Error Message"
>    Resume Normal_exit
> End Function
>
> ______________________________________
> Kath Pelletti
> Software Design and Solutions Pty Ltd
> Ph: 9505-6714
> Fax: 9505-6430
> kp at sdsonline.net
> -- 
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>
> -- 
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
> 





More information about the AccessD mailing list