Solved

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

Posted on 2016-10-25
5
35 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 119

Expert Comment

by:Rey Obrero
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 119

Expert Comment

by:Rey Obrero
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now