Results 1 to 7 of 7
  1. #1
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727

    referencing a subform from main form

    All; I have a form and subform with the following names:

    frmBasic
    sfrmCustomers

    I have a unbound txt field called txtCustID on the mainform
    I want to populate this field from a field on the subform called Cust_ID when the record is selected.

    I following in the vba event for afterupdate:

    Code:
    Private Sub cboCustNum_AfterUpdate()
       Me.Filter = "[Cust_ID]=" & cboCustNum
       Me.FilterOn = True
       
    Me.txtCustID = Forms.frmBasic.sfrmCustomers.Form.Cust_ID
    End Sub
    The name doesn't appear in the field. What am I doing wrong please?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Do you mean an unbound text box?

    Why do you need to reference the subform? Isn't the Cust_ID in the combobox?

    Me.txtCustID = Me.cboCustNum

    What if user navigates to different record in subform by clicking in subform? The textbox is no longer correct.

    What tables are these forms bound to?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    I apologize. The unbound text box is for the customer name not ID. I type the wrong field.
    txtCustName

    the main forms recordsource only contains Customer IDs and the subforms recordsource contains other customer data including the name of the customer. I wanted to put the name of the customer on the main form when the record is selected. I have an unbound combo box on the main form that selects the cooresponding cust id in the subform so that record becomes visible. Hope this helps. thanks

  4. #4
    DubCap01 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2014
    Location
    Dubbo, Australia
    Posts
    104
    I'd put a little cmdbutton on the subform, which when clicked pushes the information the other way. It the subform default view is continuous forms, then the cmdbutton would appear on each record:

    Private Sub CmdButton_Click()
    Forms!FrmBasic!Cust_ID = me.txtCustID
    End Sub

    Just give the Command button a useful name for future reference...

    cheers
    Pete

  5. #5
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    i don't understand; cmd button on the subform?

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Include the customer name as a column in the combobox RowSource then reference that column by its index. Index begins with zero.

    Me.txtCust = Me.cboCustNum.Column(1)

    Is the subform in datasheet view?

    Binding main and subform to same data source seldom works well.

    Suggest a standalone form and the search combobox in form header. Or consider split form.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    DubCap01 is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2014
    Location
    Dubbo, Australia
    Posts
    104
    Somewhere, on your subform, add a new Command Button. Then, in the On Click event, add the code I wrote above...

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

Similar Threads

  1. Replies: 9
    Last Post: 01-13-2015, 07:30 AM
  2. Replies: 6
    Last Post: 11-20-2014, 03:37 PM
  3. Replies: 4
    Last Post: 11-06-2014, 05:35 AM
  4. Replies: 3
    Last Post: 02-15-2013, 03:36 PM
  5. Referencing a form in a subform
    By 161 in forum Forms
    Replies: 3
    Last Post: 01-24-2011, 03:58 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