Results 1 to 11 of 11
  1. #1
    Star Lounger
    Join Date
    Mar 2002
    Location
    Haaltert, Belgium
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts

    not possible to lock subform (2003)

    I have a main form where is a yes/no field. When the field is yes the record may not be edited.
    That works fine, but there is a subform inside this main form and I can not locke those records.
    This is the code that I use in the subform onload
    If Forms!frmfacturatie!FacturatieHidden.Form!ynVoldaa n = -1 Then '-1 = true
    AllowEdits = False
    Else
    AllowEdits = True
    End If

    Can some one help me please?
    greetings Nancy

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: not possible to lock subform (2003)

    The On Load event of the subform will only be executed once, when the main form is opened. Don't you want to lock/unlock the subform depending on the value of the yes/no field as the user moves from record to record in the main form?

  3. #3
    Star Lounger
    Join Date
    Mar 2002
    Location
    Haaltert, Belgium
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: not possible to lock subform (2003)

    Yes indeed, but how do I do this?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: not possible to lock subform (2003)

    You need to put code in the code module for the main form, in two places:

    1) in the On Current event of the form

    Private Sub Form_Current()
    Me.SubformName.Form.AllowEdits = (Me.ynVoldaan = False)
    End Sub

    2) in the After Update event of the Yes/No field

    Private Sub ynVoldaan_AfterUpdate()
    Me.SubformName.Form.AllowEdits = (Me.ynVoldaan = False)
    End Sub

    In the above, ynVoldaan is the name of the Yes/No field on the main form, and SubformName is the name of the subform as a control on the main form. This is the name that you see if you open the main form in design view and click once on the subform, it is not necessarily the same as the name of the subform in the database window.

  5. #5
    Star Lounger
    Join Date
    Mar 2002
    Location
    Haaltert, Belgium
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: not possible to lock subform (2003)

    Hello,
    It works, but not just right jet.
    You see, I have a main form (frmfacturatie), within a hiddenform (facturatiehidden), unhidden when something is selected in the combobox.
    That hidden form has a subform (subfrmfacturatie).
    It works, but when I close fmrfacturatie (main form) I get an error. (see printscreen attached).
    So there is a form, with subform (1st subform) and that subform has also a subform (2de subform).
    I tried this code:
    In the facturatiehidden (1ste subform) I have this code:
    Private Sub Form_Current()
    If Forms!frmfacturatie!FacturatieHidden.Form!ynVoldaa n Then
    Me.subFrmFacturatie.Form.AllowEdits = (Me.ynVoldaan = False)
    Me.subFrmFacturatie.Form.AllowAdditions = (Me.ynVoldaan = False)
    Me.subFrmFacturatie.Form.AllowDeletions = (Me.ynVoldaan = False)
    Else
    End If
    End Sub

    and

    Me.subFrmFacturatie.Form.AllowEdits = (Me.ynVoldaan = False)
    Me.subFrmFacturatie.Form.AllowAdditions = (Me.ynVoldaan = False)
    Me.subFrmFacturatie.Form.AllowDeletions = (Me.ynVoldaan = False)
    AllowEdits = False
    cmdWissen.Visible = False

    On the subfrmfafcturatie (second subform) I have this code=
    Private Sub Form_Load()
    If Forms!frmfacturatie!FacturatieHidden.Form!ynVoldaa n = -1 Then
    AllowEdits = False
    AllowDeletions = False
    AllowAdditions = False
    Else
    AllowEdits = True
    AllowDeletions = True
    AllowAdditions = True
    End If
    End Sub


    When I close the mainform with the close button, I ll get this error (see jp)
    On the mainform I have this code:
    RecordSource = ""
    Me.cmbZoek.RowSource = ""
    FacturatieHidden.SourceObject = ""
    Sluiten

    I'll hope you understand it?

    greetings Nancy
    Attached Images Attached Images

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: not possible to lock subform (2003)

    I would remove the Form_Load procedure for subfrmfacturatie. Does that help?

  7. #7
    Star Lounger
    Join Date
    Mar 2002
    Location
    Haaltert, Belgium
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: not possible to lock subform (2003)

    Nope that does not help it.
    Can I put some on_error code to capture the error?

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: not possible to lock subform (2003)

    Could you post a stripped down copy of your database? See <post#=401925>post 401925</post#> for instructions.

  9. #9
    Star Lounger
    Join Date
    Mar 2002
    Location
    Haaltert, Belgium
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: not possible to lock subform (2003)

    Hello Hans,
    I adjust my code in to this:
    Private Sub Form_Current()
    On Error GoTo form_Err
    If Forms!frmfacturatie!FacturatieHidden.Form!ynVoldaa n Then
    Me.subFrmFacturatie.Form.AllowEdits = (Me.ynVoldaan = False)
    Me.subFrmFacturatie.Form.AllowAdditions = (Me.ynVoldaan = False)
    Me.subFrmFacturatie.Form.AllowDeletions = (Me.ynVoldaan = False)
    Forms!frmfacturatie!lblLocked = "Deze factuur kan niet bewerkt worden, daar ze reeds voldaan is!"
    Else
    End If
    form_End:
    Exit Sub
    form_Err:
    Resume form_End

    Resume form_End
    End Sub

    I don't get any errors anymore, is this good or not?

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: not possible to lock subform (2003)

    The problem with that approach is that you merely suppress the error message, you don't take away the cause of the error. I would test very thoroughly to check whether the form works the way you want under all circumstances. If it does, you could leave it as it is now.

  11. #11
    Star Lounger
    Join Date
    Mar 2002
    Location
    Haaltert, Belgium
    Posts
    84
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: not possible to lock subform (2003)

    Thanks, I will test it.
    I'll be back if there still is a problem.

Posting Permissions

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