Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AllowEdits False still allows Edit

Status
Not open for further replies.

Jean9

Programmer
Dec 6, 2004
128
US
From a form, I am opening a form that has two subforms and one of the subforms also has a subform. I don't want any of the forms to be editable. I am opening the form with:
Code:
    DoCmd.OpenForm sDOCNM, , , sLINKCRIT, acFormReadOnly
I can edit the form.

I have tried the following code on both the Form_load and Form_Open events of the form being opened:
Code:
    ' If opened from SFCUSTOMER_ORDER for inquiry then form should be read-only
    ' for that customer
    If Me.FilterOn = True Then
        ' Coming from another form. Make data display only
        Me.AllowAdditions = False
        Me.AllowEdits = False
        Me.SFCUSTOMER_ADDR.Form.AllowAdditions = False
        Me.SFCUSTOMER_ADDR.Form.AllowEdits = False
        Me.SFCUSTOMER_ADDR.Form.SFCUSTOMER_CONTACT.Form.AllowEdits = False
        Me.SFCUSTOMER_ADDR.Form.SFCUSTOMER_CONTACT.Form.AllowEdits = False
        Me.SFCUSTOMER_PRODUCT_XREF.Form.AllowAdditions = False
        Me.SFCUSTOMER_PRODUCT_XREF.Form.AllowEdits = False
        ' Hide the ADD/EDIT option group
        Me.OptGrpACTION.Visible = False
        Me.CbxSelRec.Visible = False
    Else
        ' Not coming from another form. Allow full range of actions.
        Me.AllowAdditions = True
        Me.AllowEdits = True
    End If
The form is STILL editable. The only time it becomes non-editable is if I click on a field in the subform and then click back to the main form. I have tried refreshing the form, changing the order of the code, seting focus to a field on the subform (which also does not work as when the form has finished loading, a field on the parent form has the focus) without success. I have stepped through the code, there is no other code firing save for the following after

Me.SFCUSTOMER_ADDR.Form.AllowEdits = False

Code:
Private Sub Form_Current()

    If Me.NewRecord Then
        sKEYCRITERIA = "[CUSTOMER_ID]=" & Me.CUSTOMER_ID & " AND [ADDR_SEQ_NO]=" & Me.ADDR_SEQ_NO
        ' Get the next default SEQ_NO
        Me.SEQ_NO.DefaultValue = GetSEQ_NO("CUSTOMER_CONTACT", "SEQ_NO", sKEYCRITERIA, _
        "NEW", Nz(Me.SEQ_NO, "0"))
    End If
    
    ' Capture Key Criteria
    sKEYCRITERIA = "[CUSTOMER_ID]=" & Me.CUSTOMER_ID & _
    " AND [ADDR_SEQ_NO]=" & Me.ADDR_SEQ_NO & " AND [SEQ_NO]=" & Me.SEQ_NO

End Sub

How can I make this form non-editable?!
Thanks in advance for any help
 
How are ya Jean9 . . .

I've seen this behavior before. Its just taken along time to dig the notes out of my library.

Bear in mind when a form is in [blue]read only mode[/blue] (Allow Edits, Allow Deletions, Allow Additions set to no/false), its only the user interface thats blocked. This is exactly what your DoCmd.OpenForm line does. However [blue]you can still write to controls thru VBA[/blue]. I found that when a form is [blue]read only[/blue] (as above), there are times when [red]a control written to thru VBA becomes editable![/red] It doesn't happen all the time which is indicitive of a bug. To ensure [blue]read only[/blue] I wound up using the [blue]Locked[/blue] property as follows:
[ol][li]Open the [blue]mainform[/blue] in design view.[/li]
[li]In the [blue]Tag[/blue] property of each editable control enter a question mark [blue]?[/blue] ([red]no quotations please![/red]). You can group select and enter once to perform this.[/li]
[li]For the subforms click the [blue]outline[/blue] to select and set their [blue]Tag[/blue] property as well. Note: [blue]you only have to select level1 subforms to lock all others on deeper levels.[/blue][/li]
[li]Save the form.[/li]
[li]In the [blue]On Load[/blue] event of the mainform ... copy/paste the following:
Code:
[blue]   Dim ctl As Control
   
   If Me.FilterOn = True Then
      For Each ctl In Me.Controls
         If ctl.Tag = "?" Then ctl.Locked = True
      Next
   End If[/blue]
[/li]
[li]Note: your still need to open the form with your [blue]DoCmd.OpenForm ReadOnly[/blue] line as this prevents additions & deletions. The [blue]Locked[/blue] property prevents editing.[/li]
[li]Thats it. Save, close and perform your testing.[/li][/ol]
[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Jean9 . . .

[blue]?[/blue]

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
I found that when a form is read only (as above), there are times when a control written to thru VBA becomes editable!
Actually, at least thru 2003, under these conditions, when a Control is written to thru code, that entire Record becomes editable, not just the Control in question! The Form resets to 'Read-Only' as soon as you move to another Record.

Linq ;0)>

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Howdy missinglinq . . .

You are correct. However in my testing I found this as well is not consistent. At times (when writing thru code ... a button that writes to a control) I'd receive the follow error message:
[blue]Error '2135':

This property is read only and can't be set.[/blue]
Go figure! ...

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Has always been consistent for me, but you know what the admen always add, "Results may vary!" ;0)>

Actually, it's this kind of quirkiness on Access' part that fascinates me, and keeps me developing apps with it! That and the fact that after a decade there's still things to learn!

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
@TheAceMan1 - I'll go with the solution you posted. I think I'll use it in addition to the code I originally posted and only for the main form because as we've all seemed to note, once the user moves focus to any of the subforms, the form's and subform's AllowEdit = false works. In a quirkiness free world, I would have preferred the whole "Allowblahblah" = false to have worked in conjunction with the opening the form in read only mode....smh...so many things to love about access...and still, so many things to grey my hair!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top