Results 1 to 5 of 5
  1. #1
    pritesharyan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2015
    Location
    India
    Posts
    32

    Referancing form in DoCmd.SearchForRecord when using Navigation form - Access

    I have a `Mainform` with `textbox` and `button` to search `subform` record
    it works fine when i directly open `Mainform` and searching desire record
    but when i open my form in `Navigaition` form it gives me error.

    [Download My Access Project] What i have tried.
    Below is my code:


    Code:
    Private Sub cmdSearch_Click()
        Dim MainFK As Long
        MainFK = DLookup("MainformID", "Subform", "SubformID =" & Me.txtSearch)
        DoCmd.SearchForRecord acDataForm, "Mainform", acFirst, "MainformID=" & MainFK
    End Sub
    Below is screen shot


    Click image for larger version. 

Name:	Question.jpg 
Views:	18 
Size:	125.3 KB 
ID:	20559
    Please guide me.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,943
    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
    pritesharyan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2015
    Location
    India
    Posts
    32
    @June7 link you have provided is for referencing control but in my case i have to reference Form. isn't it?

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,943
    Actually, you want to reference the subform container control. I always name container controls different from the object they hold.

    AFAIK, when embedding a form on a navigation control/form, have to change how the form (and therefore its controls) is referenced, even if that code is behind that embedded form.

    I don't like and never use navigation form.
    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
    pritesharyan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2015
    Location
    India
    Posts
    32
    Downlaod Project With Solution

    Code:
    PrivateSub cmdSearch_Click()
    
        Dim MainFK AsLong
        Dim rs As DAO.Recordset
        Dim WhereStr AsString
    
        MainFK = DLookup("MainformID","Subform","SubformID ="&Me.txtSearch)
    
        WhereStr ="MainformID="& MainFK
    
        WithMe.Form
    
            Set rs =.RecordsetClone
            rs.FindFirst WhereStr
    
            If _
                rs.NoMatch _
            Then
    
                MsgBox "Subform record not match to mainform record"
    
            Else
    
                .Bookmark = rs.Bookmark
    
            EndIf
    
        EndWith
    
    EndSub

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

Similar Threads

  1. Reference Form when using Navigation Form Access
    By pritesharyan in forum Access
    Replies: 3
    Last Post: 05-12-2015, 03:30 AM
  2. Replies: 1
    Last Post: 03-26-2015, 11:31 PM
  3. Replies: 5
    Last Post: 11-04-2014, 08:13 AM
  4. Replies: 12
    Last Post: 10-23-2014, 02:08 AM
  5. Replies: 3
    Last Post: 09-06-2012, 09:50 AM

Tags for this Thread

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