Results 1 to 9 of 9
  1. #1
    RonL is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Location
    NJ
    Posts
    114

    Form recordset question


    A noob question. I have a form whose recordsource is a saved query. But not all fields in the query are on the form eg. FldID or fldSortby. In VBA , how do I reference the value of say fldSortby for the current record on the form?

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Why not just put a text box on the form, bound to the appropriate field.
    What do you want to do with the value of the field.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    RonL is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Location
    NJ
    Posts
    114
    The value is for my programming purposes. Has no use for user. I know I could add a control and make it invisible, but would rather not redesign the form (used as a subform) at this stage.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    You can reference the field even if no textbox bound to it, as long as it is included the form RecordSource.
    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.

  5. #5
    RonL is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Location
    NJ
    Posts
    114
    Quote Originally Posted by June7 View Post
    You can reference the field even if no textbox bound to it, as long as it is included the form RecordSource.
    Good. But how? This, and variants of it, gives an error: varTest = frmMain.ctlsbfShotList.Form.RecordSource.[fldOrderBy]

    FldOrderBy is in sbfShotList recordsource, but there's no corresponding control on the form. How to reference? Thx, Ron

    EDIT - OK, got it. Looks like vartest = Me.ctlsbfShotList.Form.[fldOrderBy] will do it. Thank you!!
    Last edited by RonL; 10-24-2014 at 10:13 PM.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Where is that code?

    If code is behind the form that has field:

    varTest = Me!fldOrderBy

    If code is behind main form and field is in subform:

    varTest = Me.ctlsbfShotList!fldOrderBy
    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.

  7. #7
    RonL is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Location
    NJ
    Posts
    114
    Quote Originally Posted by June7 View Post
    .........
    If code is behind main form and field is in subform:

    varTest = Me.ctlsbfShotList!fldOrderBy
    It's this latter case. The code is in the main form unload event, which means the subform unload has not yet fired. My testing shows you do need the .form in the syntax (as I showed above: varTest = Me.ctlsbfShotList!Form.fldOrderBy )

    The important thing I've learned here is that each field (or calculated expression (?) if the source is a query) of a form's recordsource is available in the form's VBA, whether or not there's a corresponding control on the form. I'm still not clear on whether that means a field for which there's no control is in the form's actual recordset. Will work that out if necessary.

    Thanks! -Ron

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Works for me without the .Form maybe because I used bang (!).
    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.

  9. #9
    RonL is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Location
    NJ
    Posts
    114
    Quote Originally Posted by June7 View Post
    Works for me without the .Form maybe because I used bang (!).
    You're right! Works here too with bang. (I hadn't actually tried that before.)

    More stuff to read up on.... Thanks!

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

Similar Threads

  1. simple filtered recordset question
    By RonL in forum Access
    Replies: 3
    Last Post: 09-29-2014, 11:35 AM
  2. Replies: 6
    Last Post: 12-03-2013, 11:14 PM
  3. recordset .findfirst question
    By RonL in forum Programming
    Replies: 4
    Last Post: 06-22-2013, 01:12 PM
  4. Replies: 2
    Last Post: 03-08-2012, 12:59 PM
  5. Replies: 1
    Last Post: 11-13-2009, 03:03 AM

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