Results 1 to 2 of 2
  1. #1
    MattLewis is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2016
    Posts
    17

    Hot set current record on subform from main form's code

    How do I set the current record of a sub-form from the main form's VBA code?



    Here is where I'm at (and since I'm new to Access, this could be down the wrong pat)

    1. Main form has a listbox
    2. Main form has a subform
    3. I want the subform to select a record based on the list box current selection

    4. subform has a public subroutine that selects a record based a given parameter
    5. After update event on listbox calls that subroutine, passing it the proper parameter
    6. The subroutine on the subform is being called when expected, but the subform isn't refreshing to the show the newly selected record.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    dont use a subform, use a master form, use a combo, then you just....

    Code:
    sub cboBox_afterupdate
       me.filter = "[field]='"  & cboBox & "'"
       me.filterOn = true
    end sub

    but if you must use a subform, make 2 queries, 1 for all records, 1 that looks at the list box to filter records
    Code:
    sub lstBox_afterupdate
      if isNull(lstBox)then 
       me.subform.rowsource = "qsAllRecords
     else
       me.subform.rowsource = "qsFilterByListbox
     endif 
    end sub

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

Similar Threads

  1. Replies: 7
    Last Post: 02-18-2015, 12:07 PM
  2. Replies: 10
    Last Post: 12-17-2014, 03:31 PM
  3. Replies: 3
    Last Post: 04-23-2014, 12:19 PM
  4. Replies: 6
    Last Post: 05-18-2013, 12:48 AM
  5. Replies: 6
    Last Post: 08-22-2012, 03:24 AM

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