Results 1 to 10 of 10
  1. #1
    kimmanie is offline Novice
    Windows 8 Access 2000
    Join Date
    Sep 2015
    Posts
    5

    Go To A Record In A Subform Based On A Search Form

    I am creating a simple database for my employer but VB coding baffles me and I am stuck on the last portion of it. Some help would be greatly appreciated as I have been working on this particular coding for two days by trying different variations and researching online.


    Here's what I have:

    Parent form : woinstrfrm
    subform control: wolabfrm
    Subform name: wolabfrm_sub

    I have a <searchfrm> which allows the user to pull up a particular record on the main form based on search parameters. Two of those parameters reference the parent form and they work properly. The last search I need to filter to a record on the subform <Instorder> so it shows the associated parent form and that particular record in the subform (ideally I would prefer it didn't filter the subform but just displayed that record). The name of the text box on my search form is <IOtxtbx>

    I have tried the following:

    Private Sub IOsearch_Click()

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "woinstrfrm"
    stLinkCriteria = "Forms![woinstrfrm].[wolabfrm].Form[Instorder] = " & Me.IOtxtbx
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    End Sub

    This gives me a syntax error 3075

    So I tried this:

    Private Sub IOsearch_Click()

    Dim stDocName As String

    stDocName = "woinstrfrm"
    DoCmd.OpenForm stDocName
    With Forms![woinstrfrm]![wolabfrm].Form
    .Filter = "Me!IOtxtbx = Forms![woinstrfrm].[wolabfrm].Form[Instorder]"
    .FilterOn = True

    End With

    End Sub

    This opens the form but not to the proper record. I've been looking online and trying to adapt other formulas I've seen that are similar to my project. As I've said I'm really clueless and would appreciate any insight into my problem.

    Thank you!

  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
    Where is this code? Is it all behind the main form?

    Need code to filter the main form and also code to filter the subform? Not seeing that.

    If you want to provide db for analysis, follow instructions at bottom of my post.
    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
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870

  4. #4
    kimmanie is offline Novice
    Windows 8 Access 2000
    Join Date
    Sep 2015
    Posts
    5

    Go to a record in subform based on seperate search form

    Work Order - Copy.zip

    Here is the db. From the search form the first three filters work fine - they are linked to the main form. The last one <IOtxtbx> is supposed to link to a field on the subform (found on the main form). I cannot for the life of me figure out how to filter properly.
    Any help would be awesome.

  5. #5
    kimmanie is offline Novice
    Windows 8 Access 2000
    Join Date
    Sep 2015
    Posts
    5
    the code is behind the search form.
    I'm not sure how to properly filter the main and sub form, therein lies my problem.
    I have posted the db for analysis. Thank you.

  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
    Personally, I would integrate 'search' form into woinstrfrm. I would put the search controls in woinstrfrm form header section. Will greatly simplify applying filter to subform.

    Why is 'search' form bound to Labour table but the data you want to filter is instructions table - why is 'search' form bound to data at all? Why is textbox bound to Instorder field? Entering search value will change the record.

    I never set Caption property in table. It is just confusing, I prefer to see actual field names when viewing table.
    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
    kimmanie is offline Novice
    Windows 8 Access 2000
    Join Date
    Sep 2015
    Posts
    5
    I have moved the search controls into the main form header as suggested. I am still unsuccessful in properly coding for the <IOtxtbx> data to open the subform at the proper Instorder field. How to I get the GoToRecord to find the subform field??

  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,770
    Have to set focus on the subform container first.

    Want to provide revised db?
    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
    kimmanie is offline Novice
    Windows 8 Access 2000
    Join Date
    Sep 2015
    Posts
    5
    Work Order.zip

    Here is the update. Thank you so much .

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    The subform can only show records that are related to the main form record. Suggest you use a combobox for the Instruction Order criteria input. The RowSource would be limited to values associated with the main record. This is known as dependent or cascading combobox.

    I always give subform container name different from the object it holds, like ctrLabour.

    This code worked for me:

    Private Sub IOsearch_Click()
    Me.ctrLabour.SetFocus
    DoCmd.FindRecord Me.IOtxtbx, , , , , acAll
    End Sub

    BTW, Search is misspelled on one of the command buttons.
    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.

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

Similar Threads

  1. Display data in a subform based on Search
    By natonstan in forum Queries
    Replies: 1
    Last Post: 12-04-2014, 09:17 AM
  2. Replies: 4
    Last Post: 04-18-2014, 06:14 AM
  3. Search Main Form Based on Contents in Subform
    By MintChipMadness in forum Forms
    Replies: 1
    Last Post: 08-09-2012, 02:45 PM
  4. Replies: 4
    Last Post: 07-11-2012, 10:31 AM
  5. Replies: 13
    Last Post: 01-29-2012, 01:45 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