• From Controls

    • This topic has 6 replies, 3 voices, and was last updated 15 years ago.
    Author
    Topic
    #468845

    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

    Viewing 3 reply threads
    Author
    Replies
    • #1223287

      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.

    • #1223327

      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.

      • #1223337

        … 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.

    • #1223331

      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”?

    • #1223398

      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.

      • #1223415

        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)

    Viewing 3 reply threads
    Reply To: From Controls

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: