Selecting a subform record in Access 2013

I have a command button on my main form that opens a second form using the On-Click event but I only want the form to open after the user selects a record. How do I do verify this in code?

Anyone?
SpaceCoastLifeAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dale FyeOwner, Developing Solutions LLCCommented:
Well, generally, a record will automatically be selected, it is normally the first record in the form or subform.  However, depending on where the button is, and where the record is that you want to select (it would be useful to see a screen shot).  One method would be to use the Click event, something like:

If me.txt_ID & "" = "" Then
    msgbox "Please select a record"
Else
    docmd.openform "formname",,,"[ID] = " & me.txt_ID
EndIF
0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
If the "second form" is an actual Subform, then you can set the SourceObject after the user selects the record:

<code here to allow the user to select the record>
Me.SubFormControl.SourceObject = "YourForm"
0
SpaceCoastLifeAuthor Commented:
Sorry. I don't think I explained thoroughly enough what I'm trying to do. The subform record source includes an Id number field. What I need is when the user clicks on a record on the subform it captures that Id. The Record Selectors aren't shown in design view for either form so the On-Click event isn't available.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Dale FyeOwner, Developing Solutions LLCCommented:
The Form_Current event fires whenever you select a record.  LIke I said, an image of the form in design and Form view would be helpful.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gustav BrockCIOCommented:
Something like this in your button OnClick:

Dim varID As Variant

If Me!subNameOfTheSubformControl.Form.RecordsetClone.RecordCount = 0 Then
     ' No records in subform.
Else
    varID = Me!subNameOfTheSubformControl.Form!ID.Value
    If IsNull(varID) Then
        ' Subform is on a new record
    Else
       ' varID holds the selected ID.
        ' Open your other form.
    End If
End If

/gustav
0
SpaceCoastLifeAuthor Commented:
Perfect! One line of code and just what I was looking for.

Thanks for the help!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.