Results 1 to 7 of 7
  1. #1
    lefty2cox is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    May 2013
    Posts
    163

    Declaring and setting object variables, or just plain referencing controls

    I've been struggling with this for some time now. I have two big books, this forum and a dump truck full of internet reading and youtube videos under my belt but still can't seem to sort it out.

    I'm trying to declare and set a variable for a subform control. I've managed to write some pretty usable code over the years through pillaging and trial and error. But I obviously don't fully grasp the rules.

    I've declared some object variables in my day.. forms, controls, etc. I've used parrenthasis, dots and exclamation points. But when it works, I don't know why. Even worse, when it doesn't work, I still don't know why.



    Is there a rule of thumb for when I should be writing form.control vs form("control") or var1.var2. I know there are rules...I just can't sort them out. You folks have the unique ability to say it in a way that makes me understand.

    I would have searched this on the forum or in the reference material that I have access to, but I don't know what to call it...

    Explanations or links to prior posts are more than welcome. I know I'm often putting the cart before the horse but I'm off the leash. No formal training...running with scissors.

    Thanks

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,820
    AFAIK, a subform is not opened in Forms collection so can't really be referenced with Forms!formname or Form_formname or Form("formname"). Subforms are usually referenced through the container that holds them.
    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
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    This may help. Or This.

    Can you post a copy of your evolving database so we can see the issue or offer something?

  4. #4
    lefty2cox is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    May 2013
    Posts
    163
    Very helpful. Thank you.

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    You're giving clues about a lot of things? Maybe like Me! vs Me. and Forms! vs Forms() and maybe even Form_frmName. Then there's declaring variables, SET statements (you only SET (create) objects) and maybe it's also about SETing when all you need to do is reference, and maybe why sometimes you need parentheses in a function call. As for Forms! vs Forms() I rarely use the latter, but it is the only way I know that allows a variable to be a portion of the form name; e.g. Forms(frmName & i) where i might be an integer.

    If you have specific questions, you're probably better off to phrase a short question as a Google search and research the results. Opinions on what you find are still free here!
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    This thread should clear up the . and ! issue and may shed some light on other things.
    https://www.access-programmers.co.uk.../#post-1666571
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  7. #7
    lefty2cox is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    May 2013
    Posts
    163
    Quote Originally Posted by Minty View Post
    This thread should clear up the . and ! issue and may shed some light on other things.
    https://www.access-programmers.co.uk.../#post-1666571
    Excellent Info. Thank you.

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

Similar Threads

  1. Setting object variables
    By Glenn_Suggs in forum Programming
    Replies: 4
    Last Post: 12-05-2018, 05:02 AM
  2. Declaring Global Variables with DLookup?
    By mrmims in forum Programming
    Replies: 2
    Last Post: 09-04-2016, 07:03 AM
  3. Referencing Controls on and off a Tab
    By dccjr in forum Programming
    Replies: 2
    Last Post: 04-25-2013, 05:43 AM
  4. Referencing subform controls
    By cheyanne in forum Forms
    Replies: 7
    Last Post: 04-30-2012, 10:00 AM
  5. Referencing Controls on Forms
    By cbh35711 in forum Access
    Replies: 7
    Last Post: 04-05-2012, 09:04 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