Link to home
Start Free TrialLog in
Avatar of Fordraiders
FordraidersFlag for United States of America

asked on

i just want to make sure the subform is currently selected

i need to get values from a subform.

Before that happens, i just want to  make sure the subform is currently selected ?

if not then i need to flag them to select a row in the subform ?

Me!SubformName.Form.CurrentRecord  ?



Thanks
fordraiders
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

you can try something like this, in the Main Form's Form_Current event

Private Sub Form_Current()
    Dim rs As DAO.Recordset
    Set rs = Me.YourSubform.Form.RecordsetClone
    
    If rs.EOF Then
        MsgBox "No record in the sub form"
    Else
    
        'Refer to the Rs Object now..
    
    End If
    
    rs.Close
    Set rs = Nothing
End Sub

Open in new window

How about
Form_NameOfYourSubform.SetFocus

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Anders Ebro (Microsoft MVP)
Anders Ebro (Microsoft MVP)
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Getting a value from a subform record from the parent form or a different form is questionable at best.  How do you know what subform record you need the value from and why does a parent form need one value out of many?   I would rethink this process carefully.  If you tell us what you want to do with the selected value, we might be able to give you a better idea.

As Anders mentioned, the subform ALWAYS has a current record.  When the subform opens, the current record will be the first record in the recordset.  If the user moves focus into the subform and clicks into record 4 which makes record 4 now the current record and then goes back to the main form to do whatever you are trying to do, the current record of the subform is still #4 so your code would address #4 rather than #1 in this case.
Avatar of Fordraiders

ASKER

Ok,@anders/pat
There should be no need to add extra code, except perhaps to make sure that there is at least one record (besides the empty/newrecord) in the subform.

Yes, This is would be good also to make sure.
If you want to make sure that an "actual" record is select as opposed to a new record (In theory, it might not matter whether there ARE records, if the selected record is a new/blank record.
So, we can check whether that is the case by the use of NewRecord property:
If Me!SubformName.Form.NewRecord=True then
  Msgbox "Please Select a record in the subform. If no record exists, then please create an entry before continuing."
  Exit sub
End If

Open in new window

@Fordraiders,
This discussion would be so much more productive if you would only tell us what your end goal is.  The end goal is not - get a piece of data from a sub form.  The end goal is what you are going to do with that data once you get it.
Thanks all..