Results 1 to 2 of 2

Thread: lock main form

  1. #1
    Join Date
    Jun 2010

    Unanswered: lock main form

    I use a dialog box to select data for editing. It opens the data in a main form with tab control that has 2 pages - page1 has 2 subforms on it, page2 has 1 subform.

    Over time we realized that edits to the data are usually centered in one of these - something in the main form has changed, something in page1 has changed either subform1 or subform2, something in page2/subform3 has changed.

    I decided to add different buttons to the dialog box to get you exactly where you need to go to make changes. I need to access the main form so that the other info is visible, but locked. We need Mouse moves and tabs at a minimum.

    One button brings you to main form and locks the other 3 subforms with this code.
    Private Sub UpdateOKbtn_Click()
    On Error GoTo Err_UpdateOKbtn_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "mainform"

    stLinkCriteria = "[txtbox]=" & "'" & Me![cbobox] & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    DoCmd.Close acForm, "dialogbox"
    Forms!mainform!subform1.Enabled = False
    Forms!mainform!subform2.Enabled = False
    Forms!mainform!subform3.Enabled = False

    Exit Sub

    MsgBox Err.Description
    Resume Exit_UpdateOKbtn_Click

    End Sub

    **i also need command buttons into the subforms. I'm having trouble writing a code that will lock the main form controls and bring me into the subform shown on the button. It'll be 2 different buttons for subforms 1 & 2(this info goes together) and subform3
    I'm getting Invalid procedure call or argument with Me.AllowAdditions = False
    What version of above code will change it from main form with locked subforms to subform with locked mainform ?

    learning variations in syntax as I go! thank you for your input!!

  2. #2
    Join Date
    Mar 2009
    Provided Answers: 14
    Here's a possibility:

    In my example I have:
    - A Parent (Main) form named Mainform.
    - A Child form (SubForm) named SubForm.
    - Mainform has a subform control named Child_SubForm with its SourceObject property set to SubForm.
    - On Mainform there is also a command button named Command_SubForm.
    - On SubForm there's a command button named Command_MainForm.

    1. For each control on the parent form (Main) that must be either Disabled or Locked set the Tag property to "Lock" or to "Disable" (without quotes).

    2. Add this code to the Parent Form Module (Mainform):
    Private Sub Command_SubForm_Click()
        Me.Child_SubForm.Enabled = True
    End Sub
    Public Function EnableParent()
        Dim ctl As Control
        For Each ctl In Me.Controls
            Select Case ctl.Tag
                Case "Disable": ctl.Enabled = True
                Case "Lock":    ctl.Locked = False
            End Select
        Next ctl
    End Function
    Public Function DisableParent()
        Dim ctl As Control
        For Each ctl In Me.Controls
            Select Case ctl.Tag
                Case "Disable": ctl.Enabled = False
                Case "Lock":    ctl.Locked = True
            End Select
        Next ctl
    End Function
    Public Function DisableChild()
        Me.Child_SubForm.Enabled = False
    End Function
    3. Add this code to the SubForm Module (SubForm):
    Private Sub Command_MainForm_Click()
    End Sub
    Have a nice day!

Posting Permissions

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