Results 1 to 8 of 8
  1. #1
    TenOc is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Feb 2015
    Posts
    94

    Dim of Objects -- Form then Set equal to form name ???

    I am new to VBA but have used Access with Macros for a number of years. I have a form call it "frmAllBenf" with a sub-form call it "sfmMain". The old book I am using to teach myself VBA says to Dim as an object and then Set the object equal to the form as below.

    Dim myBenf as form
    Dim myMain as form


    Set myBenf = Forms ("frmAllBenf")
    Set myMain = Forms ("sfmMain")

    The Access 2019 VBA give me the option to Dim as below. My Question is what is the difference in the two types of Dim statements. Is there an advantage in one over the other?

    Dim myBenf As Form_frmAllBenf

    Dim myMain As Form_sfmMain

    Do I is still need a Set statement as is myBenf now = to frmAllBenf? Is there a good link to explain what the second Dim method does?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    No,they are all synonyms.
    but why the need to assign? If the user is in the form, why reference the form?
    users need the objects on the form....me.combo, or me.txtbox.

  3. #3
    TenOc is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Feb 2015
    Posts
    94
    Quote Originally Posted by ranman256 View Post
    No,they are all synonyms.

    Are you by saying "no" I do not need to Set? Or are you saying the Dim statement are synonyms?

    but why the need to assign? If the user is in the form, why reference the form?

    The user may be in a different form when the action takes place.

    users need the objects on the form....me.combo, or me.txtbox.
    See my reply in the Quote

  4. #4
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    A user normally need only work in 1 form. Everything should be in it.
    and less the need to make Dim statements to reference other forms.

  5. #5
    TenOc is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Feb 2015
    Posts
    94
    Quote Originally Posted by ranman256 View Post
    A user normally need only work in 1 form. Everything should be in it.
    and less the need to make Dim statements to reference other forms.
    I am trying to write a public function or sub that will help me accomplish the problem in my posting at https://www.accessforums.net/showthread.php?t=76267. I have 4 forms each with 3 buttons. I do not want to copy and past 12 code procedures with only small differences in the code, but it may be faster than trying to learn something new.

  6. #6
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,793
    Why start a new thread when you had 2 replies there but haven't responded?

  7. #7
    TenOc is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Feb 2015
    Posts
    94
    Quote Originally Posted by Micron View Post
    Why start a new thread when you had 2 replies there but haven't responded?
    It was a complete differ issue. The first posting was about what METHOD to use. The second posting was about IMPLEMENTATION of the method. Sorry if I should have combined the two.

  8. #8
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,793
    No apologies necessary, I'd say, but it's weird because it's really the same issue regardless of whether or not it's about the method or implementation of the method.

    What seems suspect is that you have multiple forms and you want to kick off the same procedure for all 3. Not unusual to do that for a set of controls on a form, but I think it is for multiple forms. Regardless, to answer your question, whenever you create a variable of type object you need to SET it to be some object, and when you're done with it, you should SET it to Nothing, otherwise you don't reclaim machine memory, because objects are stored there.

    Whatever it is you're doing, you might be making it more complicated than what is necessary.

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

Similar Threads

  1. Replies: 3
    Last Post: 10-15-2014, 10:09 AM
  2. Replies: 7
    Last Post: 10-11-2013, 03:28 PM
  3. Replies: 3
    Last Post: 02-17-2012, 04:43 PM
  4. Objects on the form
    By injanib in forum Forms
    Replies: 2
    Last Post: 03-19-2011, 01:48 AM
  5. Replies: 4
    Last Post: 01-27-2010, 12:39 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