Solved

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

Posted on 2016-10-25
5
82 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 51

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 51

Expert Comment

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

/gustav
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

627 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