Setting the Default Value of a Control on Form Open

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Eddie Z

    #1

    Setting the Default Value of a Control on Form Open

    I'm trying to make a dialog box pop up and ask the User for their name when they open a particular form. I then want to set the default value of a text box called "EnteredBy" to their name. However the only thing that ever appears in the text box is "#Name?" I don't know what I'm doing wrong. Can somebody please help with the code that I'm missing?

    So far, in my declarations I have:

    Code:
    Dim varUserName as String
    Then on Form Open I run the following command:

    Code:
    varUserName = inputBox(Please enter your name) 'Prompts user for their name and stores it in the variable varUserName.
    
    MsgBox (varUserName) ' Displays the value of varUserName
    
    Me![EnteredBy].defaultvalue = varUserName
    The inputBox and MsgBox funstions work properly and store the string, but for some reason I can't set the default value property control. Any help is appreciated.

    Ed
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    Hi. The defaultvalue property is a text value. As you are setting it as a string literal you will need to enclose that value in quotes:

    Code:
    Me![EnteredBy].defaultvalue = "'" & varUserName & "'"
    -Stewart

    Comment

    Working...