none
AllowEdits on subform RRS feed

  • Question

  • Hello All,

    I currently have a form... exactly-->   Supplier Details

    and a subform... exactly-->   Supplier Products Subform

    Both have this code on their OnCurrent event...

             Private Sub Form_Current()

                       Me.AllowEdits=Fale

             End Sub

    On the top form (parent form) I have an Edit button with this code as the on click event...

             Private Sub CmdEdit_Click()

                       Me.AllowEdits=True

             End Sub

    HOWEVER this AllowEdits=True does not affect the subform. I've also tried this code (and many variations) to get it to talk to the subform...

            Me.Supplier Products Subform.Form.AllowEdits=True

    ... but I still can't get the subform to stop being stubborn.

    Can someone please help?

    Thanks, Justin

    Thursday, May 31, 2018 7:17 PM

Answers

  • If I want to add a Save button next to the Edit button to do the opposite, do I change all Trues to False and add a requery cmd line

    Give it a try and let us know if you run into any problems. Good luck!
    • Marked as answer by jshot Monday, June 4, 2018 3:43 PM
    Thursday, May 31, 2018 8:54 PM

All replies

  • Hi Justin,

    I think the first problem with your syntax is caused by the spaces in your subform's name. It is considered best practice to avoid using spaces when naming objects, to avoid syntax issues like this.

    Have you tried something like?

    Me.[Supplier Products Subform].Form.AllowEdits = True

    What is important to remember is you want to use the name of the subform container rather than the name of the subform it contains. Sometimes, these names are the same, but other times, they could be different.

    Hope it helps...

    Thursday, May 31, 2018 7:24 PM
  • Thank you but no luck.

    I tried your advice with no luck. I even put this code in and took the spaces out.

    Me.[SupplierProductsSubform].Form.AllowEdits = True

    Both ways throw this error. "Microsoft cant find the field '|1' referred to in your expression."

    Does the code go in the parent form VBA or the child (subform) VBA?

    Thursday, May 31, 2018 8:28 PM
  • Hi,

    The code goes on the Parent/Main form. Also, did you make sure you were using the container's name rather than the form's?

    Posting a screenshot of the Properties Window might help with determining the correct syntax you need.

    Just a thought...


    • Edited by .theDBguy Thursday, May 31, 2018 8:31 PM
    Thursday, May 31, 2018 8:31 PM
  • What part of the properties window will be helpful in the screenshot?
    Thursday, May 31, 2018 8:36 PM
  • Also what is meant by "container name"?
    Thursday, May 31, 2018 8:37 PM
  • Thursday, May 31, 2018 8:39 PM
  • Also what is meant by "container name"?

    Hi,

    When you add a subform to a form, you are adding a subform control to the form. This is the container. The subform control then displays another form from your database, this is the form it contains (when I said "not the form it contains).

    So, in the design view of your main form, select the subform control (it's a box) and in the Properties Window, see what is in the Name property. Use this value in your code. 

    Hope it helps...

    Thursday, May 31, 2018 8:40 PM
  • it is called child 261...
    Thursday, May 31, 2018 8:42 PM
  • IT WERKED!!!!!!
    Thursday, May 31, 2018 8:43 PM
  • If I want to add a Save button next to the Edit button to do the opposite, do I change all Trues to False and add a requery cmd line
    Thursday, May 31, 2018 8:48 PM
  • IT WERKED!!!!!!

    Hi,

    Glad to hear you got it sorted out. Cheers!

    Thursday, May 31, 2018 8:53 PM
  • If I want to add a Save button next to the Edit button to do the opposite, do I change all Trues to False and add a requery cmd line

    Give it a try and let us know if you run into any problems. Good luck!
    • Marked as answer by jshot Monday, June 4, 2018 3:43 PM
    Thursday, May 31, 2018 8:54 PM
  • Thanks DBguy. Cheers
    Thursday, May 31, 2018 8:55 PM
  • And YES it worked too
    Thursday, May 31, 2018 8:56 PM
  • And YES it worked too

    Excellent! Continued success with your project.
    Thursday, May 31, 2018 8:57 PM
  • I never use the OnCurrent Event on any form for this very reason. It is unpredictable. Especially when SubForms are involved and both run code on the OnCurrent Event. The help file says:

    "This event occurs both when a form is opened and whenever the focus leaves one record and moves to another. Microsoft Access runs the Current macro or event procedure before the first or next record is displayed."

    "The Current event also occurs when you refresh a form or requery the form's underlying table or query..."

    But I have found it can also fire at other times you don't expect. I suspect your code may turning the AllowEdits property on and off at times that you can't predict. Your code:

    Me.Supplier Products Subform.Form.AllowEdits=True

    is correct assuming the code is running in a main form event procedure. So don't use OnCurrent. If you want to turn AllowEdits On and Off, just use the Command Button you already use. If you want to turn AllowEdits Off when the main form opens just use the main forms On Open Event with:

    Me.AllowEdits=False

    Me.Supplier Products Subform.Form.AllowEdits=False

    Thursday, May 31, 2018 9:14 PM
  • Hello jshot,

    Glad to hear that your original issue has been resolved.

    I would suggest you mark the helpful reply to close the thread.

    And I found that you did not come back for issue below, I would suggest you check whether it is resovled, and mark the helpful reply as answer to close it.

    Im trying to call a specific txt cell in VBA via SQL

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Friday, June 1, 2018 5:20 AM