Solved

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

Posted on 2016-10-25
5
70 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 50

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 50

Expert Comment

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

/gustav
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

761 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