Results 1 to 8 of 8
  1. #1
    Dave14867's Avatar
    Dave14867 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Location
    Upstate NY
    Posts
    376

    Accessing a subform controls

    Hello all,

    I need to access the controls on a subform in an AfterUpdate event on the main form. When I update the "CompletionDate" on the Main form, I want to access the "QtyAllocated" control on the subform. I know that to access a control on the main form I can use Me. but I have never tried to get access to the subform controls until now. I want to make the "QtyUsed" equal to the "QtyAllocated" then make the "QtyAllocated" =0.

    I am working on the "frmWorkOrders" now which uses the "frmWorkOrdersSubform2". The QtyAllocated and QtyUsed are in the subform.



    The attached file only contains sample data as I am trying a new concept for me and want to get the knack of what I am trying to accomplish.





    MRP New Design 6-26-19.zip

    Thanks

    Dave

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,429
    the way you reference a subform from the main form is

    me.subformcontrolname.form.controlname

    but your subform is a datasheet. With datasheets and continuous forms, the value that will be returned is the one for the selected record.

    It's not clear where you want to go from this point but to loop through the form controls (actually recordset) you would use something like

    Code:
    with me.subformcontrolname.form.recordsetclone
        .movefirst
        while not .eof
            'do something
            .movenext
        wend
    end with

  3. #3
    Dave14867's Avatar
    Dave14867 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Location
    Upstate NY
    Posts
    376
    Ajax,

    What I would like is to have each line of the datasheet have the respective qty's copied. Are you saying I cannot do this with a datasheet?

    I tried "me.frmworkOrder-SubForm2.Form." but I don't seem to have access to the "QtyAllocated" control.

    Is there a better method to achieve what I want to get done?

    Thanks

    Dave

  4. #4
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,429
    they don't always appear with intellisense - just type it in

    also, having none alphanumeric chars in names for table/field/control/form/report etc will cause you problems at some point down the line - typically generating a misleading error message which takes days to resolve.

    basic rule for naming

    no spaces
    no non alphanumeric chars (except underscore if you must)
    don't start with numbers
    don't use reserved words

    What I would like is to have each line of the datasheet have the respective qty's copied. Are you saying I cannot do this with a datasheet?
    no, i'm saying you need to refer to the recordsetclone and then the relevant field, not the control

  5. #5
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    This worked in a test:
    Add the code below.
    Click in a record in the sub form, click the "Save" button, then click the "Allocate" button
    Code:
    Private Sub CmdAllocate_Click()
        On Error GoTo CmdAllocate_Click_Err
    
    
        Me![frmworkOrder-SubForm2].Form!QtyUsed = Me![frmworkOrder-SubForm2].Form!QtyAllocated
        Me![frmworkOrder-SubForm2].Form!QtyAllocated = 0
    
        Me.WOStartDate.SetFocus
        Me.CmdAllocate.Visible = False
    
        Me.CmdPartsAllocated.Visible = True
        '    Me.CmdPartsAllocated.Left = 3168
    
    
    CmdAllocate_Click_Exit:
        Exit Sub
    
    CmdAllocate_Click_Err:
        MsgBox Error$
        Resume CmdAllocate_Click_Exit
    
    End Sub



    BTW, the top 2 lines in EVERY code module should be
    Code:
    Option Compare Database
    Option Explicit
    You are missing the line in blue ......

  6. #6
    Dave14867's Avatar
    Dave14867 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Location
    Upstate NY
    Posts
    376
    Steve,

    I tried the code you suggested and it doesn't work for me. I did correct the lack of Option Explicit, thanks for catching that. I had also made some other changes prior to seeing your post which I don't think would have affected it, but maybe they did. I have attached the latest file, can you see where the error is? I get an error that says "You can't assign a value to this Object".

    MRP New Design 7-3-19 -1.zip

    Thanks

    Dave

  7. #7
    Dave14867's Avatar
    Dave14867 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Location
    Upstate NY
    Posts
    376
    Steve,

    I found a way to get what I want.

    Thanks for making me think of alternatives.

    Dave

  8. #8
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Happy to help......

    Good luck with your project

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Accessing controls from navigation form
    By reynier09 in forum Access
    Replies: 2
    Last Post: 09-09-2017, 09:12 PM
  2. Replies: 5
    Last Post: 08-08-2013, 06:20 PM
  3. Replies: 2
    Last Post: 07-25-2012, 05:03 PM
  4. Accessing form controls
    By dante in forum Forms
    Replies: 15
    Last Post: 07-28-2009, 08:26 AM
  5. Accessing subform fields
    By nkenney in forum Forms
    Replies: 1
    Last Post: 04-21-2009, 10:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums