Solved

how to select a record in a subform datasheet using  code in main form. MS access 2016

Posted on 2016-10-25
5
57 Views
Last Modified: 2016-10-27
how to select a record in a sub-form datasheet using  code in main form?  MS access 2016

using code behind main form:
e.g. I want to select the sub form id 200 in the datasheet.
when I push a button on the main form.

thanks
0
Comment
Question by:john
  • 2
  • 2
5 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 41859396
try this codes

private sub button_click()
with me.subformcontrolName.form.recordsetclone
     .findfirst "[ID]=200"
     if not .nomatch then
         me.subformcontrolName.form.recordsetclone.bookmark=.bookmark
     end if

end with
end sub

for dynamic  record id selection, use a control In the main form that display the "[ID]" number
0
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 41859850
This should do:

Private Sub YourButton_Click()

    Dim rst As DAO.Recordset
    Dim Id As Long

    If Not Me.NewRecord Then
        Id = Me!Id.Value
        With Me.YourSubformControlName.Form
            Set rst = .Recordsetclone
            rst.FindFirst "[ID] = " & Id & ""
            If rst.NoMatch = False Then
                .Bookmark = rst.Bookmark
            End If
        End With
    End If

    Set rst = Nothing

End Sub

Open in new window

/gustav
0
 

Author Closing Comment

by:john
ID: 41863080
Only Gustav Brock's solution worked.  thank  you
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 41863092
what  was wrong with the code I posted?
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 41863407
Rey, are you serious? Too little coffee? Look again.

/gustav
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question