Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2005
    Posts
    220

    Unanswered: Set Focus on form

    I have 2 forms. The first one has a groupbox where the user selects their username, and an option box where they choose either group1, group2, or group3.

    The second form has a variety of fields that I want the user to fill out. These fields are in groups. Group1 may have 10 fields, Group2 has 5, and Group3 has 12.

    Now, what I want is this: When the user selects Group1 from the first form, I want the fields in Group2 and Group3 to be greyed out. I don't want the user to be abe to update any of them. If they choose Group2, groups 1 & 2 will be greyed out, etc.

    How do I do this?

  2. #2
    Join Date
    Apr 2004
    Location
    outside the rim
    Posts
    1,011
    Since Acces doesn't let you create control arrays (directly) like VB does, you have to either do it manually, or get a little creative.

    A neat little trick is to use the Tag property. Put a 1 in the Tag for all group 1 controls, ditto for groups 2 and 3.

    Using code similar to the following, you can enable and disable the desired controls. This code I snabbed from my current project where the user complets the form in stages, so groups of controls get enabled at a time (similar to what you're asking for):
    Code:
    Public Sub MoveFocus(EnableControl As String, DisableControl As String, FormName As String, WithLock As Boolean)
    
        Dim ctl As Control
        Dim frm As Form
        
        Set frm = Forms(FormName)
        On Error Resume Next
        For Each ctl In frm.Controls
            If WithLock Then
                If ctl.Tag = EnableControl Then ctl.Locked = True
                If ctl.Tag = DisableControl Then ctl.Locked = False
            Else
                If ctl.Tag = EnableControl Then ctl.Enabled = True
                If ctl.Tag = DisableControl Then ctl.Enabled = False
            End If
        Next
        If Err Then Err.Clear
    
        Set ctl = Nothing
        Set frm = Nothing
    End Sub
    Have fun. As always, there are various ways - somebody will likely post a better way

    tc
    have fun!

    Todd S.
    click to email


    Independent Development Consultant
    Biz db & reports - SQL, Access, Crystal, Seradex and more
    Small, custom, unique programs - Office, VBA, .NET


    _________________________________________________
    Favorite message from Windows:
    There was an error displaying the previous error message

    Sadly, there was no error number to look up ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •