Results 1 to 4 of 4
  1. #1
    tylerg11 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    200

    Get value from first record in subform

    With VBA I need to access my subform from the main form. I am trying to specifically retrive the value from the first record of the subform. The following doesn't always work.



    Code:
    Me![Subform].Form![Field]
    If gives me a value, but it isn't always the first one in the subform. Any ideas as to some syntax I need to get that first value?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I always give subform container control a name different from the object it holds, like ctrOrders.

    Possible options (not all tested):

    1. move to the first record of the subform, try:
    DoCmd.GoToRecord Me.subformname, , acFirst

    2. open RecordsetClone of the subform and read value from first record of the recordset, like:
    Me.subformcontainername.Form.RecordsetClone!fieldn ame

    3. a textbox in subform (in Continuous view) footer with expression like: First(fieldname) then textbox on main form refers to the textbox in subform footer
    Me.subformcontainername.Form.textboxname

    4. DLookup to get value from table, would need same filter criteria applied to the subform
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    tylerg11 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    200
    I've tried

    Code:
    DoCmd.GoToRecord Me.subformname, , acFirst
    But then how do I reference the actual value of that record?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Set a variable or textbox.

    strData = Me.subformcontainername.fieldname

    or

    Me.textboxname = Me.subformcontainername.fieldname

    Use the actual names of your controls and forms.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 08-22-2012, 03:24 AM
  2. Replies: 5
    Last Post: 08-21-2012, 12:30 PM
  3. Replies: 14
    Last Post: 05-25-2012, 02:40 AM
  4. Replies: 6
    Last Post: 05-05-2012, 08:43 AM
  5. Replies: 7
    Last Post: 07-15-2011, 01:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums