Results 1 to 4 of 4
  1. #1
    orcinus is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2010
    Posts
    67

    Setting A Control To A Variable That is Not the Control's Value, but the Control itself..

    **Sorry, am now using Access 2013** will update my profile



    So I want to set the control in a form I want to use in a statement like this:

    if var1 = 1 then make var2 = control1
    if var1 = 2 then make var2 = control2

    The trouble is that when I do this, more specifically as:

    Set ctrlCondChk = Forms("Template_Project").Controls("DESC_TemplateS tatus") 'for when var1 = 1
    Set ctrlCondChk = Forms("Template_Project").Controls("ChkReason") 'for when var1 = 2


    ..the variable ctrlCondChk takes on the value that is in the control DESC_TemplateStatus!

    However, I do not want the value, I want the field/control itself to be assigned the variable so I can use it later in my code..

    ctrlCondChk will take on either DESC_TemplateStatus or ChkReason and then at that time, the value in one of these fields (depending on which is being activated by Var1) will be compared to a value..

    So for the first iteration, I want to use a particular control/field and for the second iterative pass, I want to change the control/field that is referenced.

    So, in summary then:

    if var1 = 1 then make var2 = DESC_TemplateStatus
    if var1 = 2 then make var2 = ChkReason

    Then when iterating through another part of the code on say, iteration 1:

    if var1 = "Active" then..do something 'for example, in this iterative loop wanting to see if DESC_TemplateStatus has the value "Active"

    or if it is on iteration 2, then var1 should take on the 2nd control (not value, but the control itself..!)

    If var1 = "Charge" then..do something..'for example, in this iterative loop, want to see if ChkReason has the value "Charge"

    The reason is that the control being compared will change depending on the number of the iterative loop the code is currently on and instead of changing the control each time, I would rather set the change early in the code and then reference only one variable..

    Thanks for any help!

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Set ctrlCondChk = Forms("Template_Project").Controls("DESC_TemplateS tatus") 'for when var1 = 1
    Set ctrlCondChk = Forms("Template_Project").Controls("ChkReason") 'for when var1 = 2
    How did you declare "ctrlCondChk"? What data type?
    How did you declare "var1"? What data type?


    It would be helpful to see your code.......




    If you declared ctrlCondChk like this:
    Code:
        Dim ctrlCondChk As Control
    You could have
    Code:
        Set ctrlCondChk = Forms("Template_Project").Controls("DESC_TemplateStatus")
    Then
    Code:
        var1 = ctrlCondChk
    would set var1 = the the value of ctrlCondChk (which is Forms("Template_Project").Controls("DESC_TemplateS tatus") )
    if "var1" datatype was the same as the control "DESC_TemplateStatus".

  3. #3
    orcinus is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Apr 2010
    Posts
    67
    Thanks for the response..

    My apologies, I think I confused the heck out of this, by mixing up my variables..

    I also think I may have mixed up what I want to do by trying to make the variable equal the "control" itself as opposed to the control value.

    I think my code may work as I have it now, so let me rethink this and try it with using the actual value itself and see if it works..If it doesn't, I will post again and see if I can narrow down or articulate what I need better..

    Sorry for the confusion!

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Sounds like a plan. Good luck.....

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

Similar Threads

  1. Replies: 15
    Last Post: 05-12-2016, 02:27 PM
  2. Replies: 4
    Last Post: 02-18-2016, 12:06 PM
  3. Replies: 1
    Last Post: 10-06-2015, 06:50 AM
  4. Replies: 8
    Last Post: 06-19-2015, 02:19 AM
  5. Replies: 3
    Last Post: 03-29-2012, 12:40 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