Results 1 to 7 of 7

Thread: From Controls

  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    USA
    Posts
    386
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Is there a way to increment the names of form controls?

    Example:

    Forms![Frm_MerchOps Calendar].[Date_1].Caption

    Is the a way to create a loop that would increment this to become Forms![Frm_MerchOps Calendar].[Date_2].Caption, Forms![Frm_MerchOps Calendar].[Date_3].Caption, etc?


    Thanks
    Richard

  2. #2
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts
    There is a way to do that using VBA, but the subject is beyond the scope of a thread. In general, you will need to understand the Access Object Model (it changes slightly depending on the version you are using), and the basic process is to find the form in the Forms collection, and then iterate through the Controls collection changing the control name, and then saving the form. It is not a trivial task, and unless you have to do this repeatedly, I would do it manually.
    Wendell

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    USA
    Posts
    386
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This will be a repeaative task. We are building a grid on a from and depending on the month selected would like for the text box at the top of the grid to show the date for that square.

    I will take a look at the Object Model and see what we can come up with.


    Thanks for the help.
    Richard

  4. #4
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts
    Quote Originally Posted by Aheron View Post
    Is there a way to increment the names of form controls?

    Example:

    Forms![Frm_MerchOps Calendar].[Date_1].Caption

    Is the a way to create a loop that would increment this to become Forms![Frm_MerchOps Calendar].[Date_2].Caption, Forms![Frm_MerchOps Calendar].[Date_3].Caption, etc?


    Thanks
    What do you mean by "increment the names"?
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  5. #5
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts
    Quote Originally Posted by Aheron View Post
    ... We are building a grid on a from and depending on the month selected would like for the text box at the top of the grid to show the date for that square.
    Are you sure you want to change the name of the control to make that happen? I don't know what else the grid is supposed to display, but if you are showing the day of the month, that would be just setting the value for that control. And I certainly wouldn't want to be renaming controls on a form while they were open - in fact what you would need to do is open the form in design view, change the name of the control, save it, and then open it in display mode. It is an ugly process, and would cause significant delays in displaying the form, and database bloat. But if you want to set the value of a control in display mode that is pretty straightforward.
    Wendell

  6. #6
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    USA
    Posts
    386
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No, I think I misstated. We are not wishing to change the name of the control, just the contents of the control. txtDate_1 would always be txtDate_1, but depending on the month selected by the user, the contents would change.
    Richard

  7. #7
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts
    Quote Originally Posted by Aheron View Post
    No, I think I misstated. We are not wishing to change the name of the control, just the contents of the control. txtDate_1 would always be txtDate_1, but depending on the month selected by the user, the contents would change.
    I thought that's what you meant, but wasn't sure. In that case, it is simple and here is an example:

    Dim N as Integer

    For N=1 to 7 'or whatever your max # is
    Forms![Frm_MerchOps Calendar]("Date_" & N).Caption = ... whatever you want...
    Next N

    If the controls are on the same for in which code is processing, you can use: Me("Date_" & N)
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •