Results 1 to 8 of 8
  1. #1
    Join Date
    May 2012
    Posts
    6

    Unanswered: Locking edits to Main form whilst the Sub-Form is visible

    I have a Main Form in which a Sub Form will pop up on the bottom of the Main Form, if certain criteria within the Main Form are selected. I don't want the user to be able to edit the Main Form while the Sub Form is visible. I have a button on the Main Form that the user can press, in order to hide the Sub Form (after filling out the Sub Form). How do I go about not allowing edits in the Main Form while the Sub-Form is visible; then allow edits to the Main Form again after the toggle button (to hide the Sub Form) is pressed?

  2. #2
    Join Date
    Aug 2004
    Location
    Cary, NC
    Posts
    264
    From what I can gather from the question, when the user selects certain criteria on the main form you need to prompt them for additional information before they can continue editing. The simplest, and safest, way to do this is to open a second form when needed by the main form. Set the modal property on this popup form to true and they will have to deal with it before going back to the main form.

    Steve

  3. #3
    Join Date
    May 2012
    Posts
    6
    Actually, what happens is, if they enter a "Fail" against a serial number, then the Defect Entry Sub-Form pops up, where they enter the details of the defect (Defect Description, etc.). While this sub-form is opened, I don't want them to be able to edit the main form.

  4. #4
    Join Date
    Aug 2004
    Location
    Cary, NC
    Posts
    264
    Then that's a perfect scenario for what I described...

    When they enter a "Fail" open up a separate Defect Entry form which has the modal property set to true.

    It's the easiest way to ensure that they enter the details of the defect before continuing to edit main form.

    Steve

  5. #5
    Join Date
    May 2012
    Posts
    6
    I have tried setting the Modal Property of my sub-form to "Yes", but I am still able to edit fields in the main form. Not sure why this is.

  6. #6
    Join Date
    Aug 2004
    Location
    Cary, NC
    Posts
    264
    Instead of the current process where the Defect Entry form is a subform of the main form, make the Defect Entry form independent of the main form. When you would normally make the subform visible just open it instead. If the Defect Entry form is set as Modal the user won't be able to do anything else until they close the form.

    Steve

  7. #7
    Join Date
    May 2012
    Posts
    6
    Here is the code I use on the main form, in order to determine whether to open the sub form. Are you saying I should use the OpenForm command?

    Private Sub PassOrFail_AfterUpdate()

    If Me.[PassorFail] = "P" Then

    Me![SN].SetFocus
    DoCmd****nMacro "Mac_NextRecord"

    Me!SN = ""
    Me!PassorFail = ""

    Me![tbl_DefectFound].Visible = False

    Me![SN].SetFocus


    End If

    If Me.[PassorFail] = "F" Then
    Me.[tbl_DefectFound].Visible = True
    Else
    Me.[tbl_DefectFound].Visible = False

    End If

    End Sub

  8. #8
    Join Date
    Aug 2004
    Location
    Cary, NC
    Posts
    264
    It's off topic but is PassorFail a text field? Hopefully your form restricts the entries to P or F or your logic won't work. It would be safer to use one of the controls that is meant for this purpose.

    Also, you can combine both of your if statements into in an if/else.

    My answers have all been aimed at having you create a simple popup form that would take the defect details. This would not be part of the main form but a separate form just for gathering the details of a defect. If this defect form (frmDefectDetails in my example) has the modal property set to true then the user will have to close it before continuing with the main form. You can do any kind of data transfer or validity checks that you need at that point. If you didn't get the answers you wanted from the user just open the form again.

    Based on the snippet you provided, I would do something like this:

    Code:
    Private Sub PassOrFail_AfterUpdate()
    
      If Me.[PassorFail] = "P" Then
    
        Me![SN].SetFocus
        DoCmd****nMacro "Mac_NextRecord"
    
        Me!SN = ""
        Me!PassorFail = ""
    
      else
    
        DoCmd.OpenForm "frmDefectDetails"
        
      End If
    
    End Sub
    If you need to run the NextRecord macro after the defect details are entered as well, then do this instead:

    Code:
    Private Sub PassOrFail_AfterUpdate()
    
      If Me.[PassorFail] = "F" Then
    
        DoCmd.OpenForm "frmDefectDetails"
        
      End If
    
      Me![SN].SetFocus
      DoCmd****nMacro "Mac_NextRecord"
    
      Me!SN = ""
      Me!PassorFail = ""
    
    End Sub

    Steve

Posting Permissions

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