Results 1 to 7 of 7
  1. #1
    Phred is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2009
    Posts
    246

    DoCmd.FindRecord not sure what the best choice is.

    Access 2007, back end SQL Server 2008. It is easier to show you my code then try to explain it.



    Code:
    Private Sub EntityID_DblClick(Cancel As Integer)
    
    Dim intEntityID As Integer
    
    Dim intNewID As Integer
    
    intEntityID = [Forms]![Property]![PropertyEntityJoin].[Form]![EntityID] 'gets the primary key that you want to find in EntityFRM.
    
    DoCmd.OpenForm "EntityFRM" 'Opens EntityFRM
    
    Me.EntityID.SetFocus 'sets the focus on the field EntityID in the EntityFRM
    
    intNewID = DLookup("EntityID", "dbo_entity", "EntityID = " & intEntityID & "") 'Finds and confirms that the EntityID that I want to find actually exists and returns it to the variable Dim intNewID As Integer
    
    DoCmd.FindRecord Here is where I get in trouble. I have the primary key of the record I want to display but I don't know how to find and display it. This should be easy. 
    
    End Sub
    I can't seem to find the proper way to display the record.

    Thanks,

    Fred

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,967
    Options:

    1. Provide arguments that fit your requirement, maybe: DoCmd.FindRecord intNewID, acEntire, , acSearchAll, , acAll

    2. set the form Filter and FilterOn properties

    3. use RecordsetClone and Bookmarks
    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
    Phred is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2009
    Posts
    246
    I tried this. Each line seems to work correctly but I cannot get the form to show the found record. The FindRecord arguments seem correct. It does not error out at all.

    Dim intEntityID As Integer
    Dim intNewID As Integer
    intEntityID = [Forms]![Property]![PropertyEntityJoin].[Form]![EntityID]
    DoCmd.OpenForm "EntityFRM"
    Me.EntityID.SetFocus
    intNewID = DLookup("EntityID", "dbo_entity", "EntityID = " & intEntityID & "")
    DoCmd.FindRecord intNewID, acEntire, , acSearchAll, , acAll
    Me.Refresh

    Should there be some other method besides Me.Refresh?

    Thanks

    Fred

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,967
    Shouldn't need the Me.Refresh

    The FindRecord code works for me.

    Are you trying to search a subform? Is the button on main form? Review https://www.accessforums.net/forms/f...ure-45926.html
    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
    Phred is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2009
    Posts
    246
    There is no button. The user double clicks on a field in the sub form to launch the code. I have attached two JPGs.

    Property Screen (directly below) has a subform called PropertyEntityJoin_FRM forms the join between the Property table via PropertyFRM and the Entity table. It is a parent child screen (1 to many) linked by Primary keys.

    Click image for larger version. 

Name:	Propertyentity.JPG 
Views:	16 
Size:	63.5 KB 
ID:	17734

    The user wants to find the corresponding Entity on the EntityFRM so..

    The user double clicks on the EntityID (highlighted in yellow). The code grabs the EntityID field which happens to be the Primary key for the Entity form/table.

    It opens the Entity form (see Entity JPG) and sets the focus on the EntityID field which is in the main form EntityFRM, sets focus on field EntityID, and then runs the findrecord code. It should bring up the matching record.

    This allows the user to jump quickly from the Property screen to the entity screen and find the right Entity.

    Click image for larger version. 

Name:	EntityScreen.JPG 
Views:	16 
Size:	56.0 KB 
ID:	17735

    Thanks,

    Fred

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,967
    Regardless of what event (button click or textbox double click) is used for the search code, the issue is the same.

    Your images don't relate. Property image shows 20 was selected in the subform but shows 14 in the Entity image.

    I don't understand why you want the FindRecord code.

    Open the Entity form filtered to the EntityID selected in the Property subform.

    DoCmd.OpenForm "Entity", , , "EntityID=" & Me.EntityID
    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
    Phred is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Dec 2009
    Posts
    246
    Hi June7:

    Sorry for the mismatch on the screen snaps. It was sloppiness on my part. I didn't necessarily want the "FindRecord" I was just looking for the correct way and it seemed like a good choice with my limited experience. Your code below did the trick.

    DoCmd.OpenForm "Entity", , , "EntityID=" & Me.EntityID

    Thanks for your patience.

    Fred

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

Similar Threads

  1. FindRecord Problem
    By zareh in forum Programming
    Replies: 10
    Last Post: 02-27-2014, 12:22 PM
  2. FindRecord Crash if criteria not found
    By quicova in forum Programming
    Replies: 4
    Last Post: 09-13-2013, 08:42 AM
  3. can not use FindRecord with string
    By john60 in forum Programming
    Replies: 2
    Last Post: 08-10-2013, 08:25 AM
  4. Filter or FindRecord in Split Form
    By P5C768 in forum Forms
    Replies: 4
    Last Post: 03-20-2012, 12:16 PM
  5. Can you use a parameter in findrecord?
    By P5C768 in forum Programming
    Replies: 2
    Last Post: 08-20-2009, 04:36 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