Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2011

    Unanswered: Open a form with a variable name

    I'm trying to save myself some necessary coding in the future.

    I have several forms, and each user has their own unique form based on their LAN ID.

    I currently can get those forms to open by using "WindowsUserName" in the Form's name. This is great because I won't have to go back to this code and change everything when those people who use the database change jobs. I only have to change the name of the form.

    However, on their personal forms, I have put in some status bars, and various tools that references the name of the form.

    - Where it says "LAN ID" that's the unique LAN ID of that user.

    Forms!["Working Form - LAN ID]!StatusBar8.Panels(1).Text = "Opening up backend table..."

    I tried this line of code:
    Forms!["Working Form - " + WindowsUserName + "]!StatusBar8.Panels(1).Text = "Opening up backend table..."

    I tried various subset uses of the quotation marks around the Sub "WindowsUserName" and to no avail I continue to receive a debugging error.

    I tried substituting the name of the form as a variable itself, and Access totally doesn't like that idea either.

    I have come to terms with the possibility that I will just have to place into my coding documentation that if and when the user's LAN ID changes I can utilize the "Replace Text" feature in the coding environment and just change the user's lan id there.

    But that would just make me have to do work, and I like to be lazy lol

    So.... if there is a way to put my variable in there to call the LAN ID of the current user opening that form, it would make my life easier, if not... then... that's OK too.

  2. #2
    Join Date
    Sep 2011
    I should probably mention that I used the "plus signs" as my last ditch effort to figure out how VBA wanted me to concatenate this line of code.... it didn't like the plus signs either.

  3. #3
    Join Date
    Mar 2009
    Provided Answers: 15
    If the form for a user whose WindowsUserName is "john.doe" is named "Working Form - [john.doe]", it should be:
    Forms("Working Form - [" & WindowsUserName & "]").StatusBar8.Panels(1).Text = "Opening up backend table..."
    provided that StatusBar8.Panels(1).Text = "Opening up backend table..." is correct.
    Have a nice day!

Posting Permissions

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