Results 1 to 9 of 9
  1. #1
    fhickler is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Nov 2018
    Posts
    30

    Editable textbox to update subform

    I'm still a bit of a novice at Access and VBA, so this may seem trivial, but this is what I'm trying to achieve:




    Table - call it Table1 - which includes a field called Field1
    A form that contains the following:
    - A subform of Table1 - call it subTable1 - in datasheet format
    - A textbox - call it Textbox1 - that displays value of Field1 of record selected in subTable1

    Easy enough.


    BUT I want Textbox1 to be editable and, when edited, to update also in Table1. What would be an uncomplicated way to achieve this?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    How would a textbox in the main form know which record to update? Without specifying, it would update the first or currently selected record. An update query could work, or code that updated the active record in the subform.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    fhickler is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Nov 2018
    Posts
    30
    Quote Originally Posted by pbaldy View Post
    ...or code that updated the active record in the subform.
    Maybe that's the way to go. Any ideas to point me in the right direction?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    In the after update event of the textbox:

    Me.SubformControlName.Field1 = Me.TextboxName

    More here on referring to controls on forms/subforms:

    http://theaccessweb.com/forms/frm0031.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    fhickler is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Nov 2018
    Posts
    30
    Me.SubformControlName.Field1 = Me.TextboxName
    That sounds promising. But one problem is the field isn't editable. It's a plain text field who's control source is =[subTable1].[Form]![Field1]. I'm guessing that if it has a control source of another field then that would make it not editable. But I want it to display the current value of the field AND be editable. So maybe have it be unbound with no control source, and then fill it with a value when the main form initializes via code (basically the reverse of the code you cite)? Am I guessing correctly? What would that line of code look like?

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The line of code wouldn't change, you'd just add it to the main form's load event too. Or current event.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    In the OnCurrent event of the subform add Me.Parent.Form.Controls("TextBoxName")=Me.Field1. Then do what Paul said in the AfterUpdate of the textbox on the main form. Leave the textbox unbound.

    Cheers,
    Vlad

  8. #8
    fhickler is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Nov 2018
    Posts
    30
    Thanks everyone. This should work great.

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem, post back if you get stuck.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 5
    Last Post: 04-30-2015, 01:50 AM
  2. Replies: 5
    Last Post: 07-15-2014, 09:56 PM
  3. Unbound Form and Editable Subform
    By tndinnc in forum Forms
    Replies: 6
    Last Post: 04-19-2013, 05:42 PM
  4. Updatable & editable subform?
    By jfn15 in forum Forms
    Replies: 2
    Last Post: 06-21-2011, 10:35 AM
  5. Replies: 3
    Last Post: 02-10-2010, 07:29 AM

Tags for this Thread

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