Results 1 to 5 of 5
  1. #1
    bbrazeau is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    101

    Using DoCmd.FindRecord on nested subforms

    Below is code I wrote to try and allow the user to search all records for a Part Number and then go to the record that has that number.
    I have a combo box on the main form that is unbound but gets its data from the same record source as the sub-subform. The user picks a part from the combobox then presses the Part button.The code works the 1st time and usually more than once. It almost seems as though as long as its searching forward it finds and moves to the correct record, but if you try to go backwards its just finds the customer and the first record for that customer. Does anyone see a issue that sticks out?



    Code:
    Private Sub cmdPartSearch_Click()
       Dim frm As Form
       Set frm = Forms!Main.Form!Molds.Form
       Dim Cust, lngMold, lngPart As Long
       Cust = Me.cboPartSearch.Column(2)
       lngMold = Me.cboPartSearch.Column(3)
       lngPart = Me.cboPartSearch.Column(0)
       MsgBox Cust & " " & lngMold & " " & lngPart
       CustomerID.SetFocus
       DoCmd.FindRecord FindWhat:=Cust, Match:=acEntire, MatchCase:=False, _
          Search:=acSearchAll, SearchAsFormatted:=False, _
          OnlyCurrentField:=acCurrent, FindFirst:=True
       Forms.Main.Molds.SetFocus
       DoCmd.FindRecord FindWhat:=lngMold, Match:=acEntire, MatchCase:=False, _
          Search:=acSearchAll, SearchAsFormatted:=False, _
          OnlyCurrentField:=acCurrent, FindFirst:=True
       frm.Parts.SetFocus
       DoCmd.FindRecord FindWhat:=lngPart, Match:=acEntire, MatchCase:=False, _
          Search:=acSearchAll, SearchAsFormatted:=False, _
          OnlyCurrentField:=acCurrent, FindFirst:=True
       CustomerID.SetFocus
       Me.cboPartSearch = Null
       Set frm = Nothing
       Me.Repaint
    End Sub
    Click image for larger version. 

Name:	mainform.jpg 
Views:	10 
Size:	74.2 KB 
ID:	29952
    Last edited by RuralGuy; 08-15-2017 at 11:27 AM. Reason: Added code tags and indenting

  2. #2
    bbrazeau is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    101
    Found that if MoldID is the active control when choice is made from combobox and Part button is pushed it works everytime. However I can't find a way to make that control active in code. I can't rely on the user allways having that control be the last one they were in.

  3. #3
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Have you reviewed this link yet? http://theaccessweb.com/forms/frm0031.htm

  4. #4
    bbrazeau is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    101
    Hi RG Thanks. Yes I had referenced to the link you posted. I have it as a document I use, but I was still having trouble. Finally got it to work by as I mentioned getting the focus back to the MoldID field excerpt from code below

    Forms.Main.Molds.SetFocus
    Molds.Form.Parts.SetFocus
    DoCmd.FindRecord FindWhat:=lngPart, Match:=acEntire, MatchCase:=False, _
    Search:=acSearchAll, SearchAsFormatted:=False, _
    OnlyCurrentField:=acCurrent, FindFirst:=True
    Me.cboPartSearch = Null
    frm.MoldID.SetFocus

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    That's great. Are you ready to mark this thread as Solved?

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

Similar Threads

  1. Replies: 4
    Last Post: 09-29-2015, 01:40 AM
  2. Nested subforms
    By peter_mikael in forum Forms
    Replies: 1
    Last Post: 09-24-2015, 01:36 PM
  3. Replies: 6
    Last Post: 08-09-2014, 01:09 PM
  4. Replies: 11
    Last Post: 01-09-2012, 11:40 AM
  5. Replies: 0
    Last Post: 06-29-2010, 12:04 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