Results 1 to 10 of 10
  1. #1
    msmithtlh is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    151

    Autofill text box based on selection in combo box.

    I have read the post and answers in the autofill post by dbell. I am having similar issues.

    I have a form with nested subforms. In the second subform, I have a combo box, where I select a record and fill one field (based on a query). Based on the record selected in the combo box, I want to also fill a text box in the same subform. I have tried multiple things and can't find the one that works. This seems like it should be simple but I have spent a couple of days fighting with this one detail.



    SQL from combo box query:
    SELECT BPFieldsByTask.BPField, BPFieldsByTask.Score, BPFieldsByTask.Task
    FROM BPFieldsByTask
    WHERE (((BPFieldsByTask.Task)=[Forms]![SUNTAX Header]![Task]))
    ORDER BY BPFieldsByTask.BPField;

    This lets me select and populate the BPfield. I want to also fill the "score" field in the same subform, based on the BPfield selected. When the query is run independently, it gives the correct value for the "score" field. I just am having trouble getting the value into the control on the form.

    Thanks in advance.

  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,625
    Expression in textbox ControlSource can reference the relevant column index of combobox. Index begins with 0 so the index for the Score column is 1.

    =[comboboxname].[Column](1)

    If you want to save the Score to record, that will require code, but is saving the value necessary?
    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
    msmithtlh is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    151
    That got it to display. Yes, I need to save the value to the score field. Can I do that on the "dirty" event?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    I've never used Dirty event but that might do the job. Or form BeforeUpdate event.
    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.

  5. #5
    msmithtlh is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    151
    Please help with code to save the data. Thanks.

  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,625
    Assuming Score field is included in the form RecordSource, the code is simple.

    Me!Score = Me.textboxname

    The real trick is picking the event(s) to put the code in.
    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
    msmithtlh is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    151
    Both are name score, so I have Me!Score = Me.Score - but it isn't saving the value.

    I tried it in "on change" event and "on dirty" event.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    Events of what - form or control? I would not recommend the OnChange.

    Is the code executing? Step debug. Refer to link at bottom of my post for debugging guidelines.

    Try the combobox AfterUpdate or the form BeforeUpdate.
    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.

  9. #9
    msmithtlh is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    151
    Not having any luck. I've tried it several places. Am getting an error that says I can't update this object. Is the syntax more involved since I am in a subform?

  10. #10
    msmithtlh is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    151
    I got it!! Saw a similar post, and the "light dawned." Thanks so much!!!

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

Similar Threads

  1. Replies: 1
    Last Post: 12-10-2013, 06:27 AM
  2. AutoFill Based on ComboBox Selection
    By chelseagardens in forum Forms
    Replies: 3
    Last Post: 08-08-2013, 01:14 PM
  3. Autofill field based on combo box
    By topp in forum Access
    Replies: 2
    Last Post: 06-26-2012, 04:36 PM
  4. Replies: 3
    Last Post: 03-15-2012, 02:27 PM
  5. Replies: 8
    Last Post: 01-25-2012, 02:07 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