Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2010
    Posts
    88

    Unanswered: Setting DefaultValue from a variable.

    I have a text field bound to a control on a normal data entry form. I want there to be a default value for this field ... but this should be configurable. I really do mean a default value - I don't want to just fill it in as soon as the form is opened (otherwise any "new" record instantly becomes populated and I end up with a file full of almost empty records...)

    I have an "admin" screen where an admin user can set the string to whatever.

    In my data entry form I have a Form_Open event routine which reads the string from where it was stored in the admin screen, and puts it in a string variable (private to the form) called "CurrentDefault".

    So now, also in the Form_Open routine, I want to set the default value for the control ... If I say

    txtControl.DefaultValue = """Hello World"""

    then the default value is set.

    But if I say

    txtControl.DefaultValue = CurrentDefault

    then it doesn't work, I see #Name?

    I've tried variants like "" & CurrentDefault & ""
    but I'm getting lost in my quotes and strings, can anyone sort me out?

    TIA

  2. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    In the first example you're assigning a literal, Hello World, but in the latter Access has to retreive the variable CurrentDefault. The Form_Open event may be too early to perform this retrieval. Try moving your code to the Form_Load event instead.

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    Join Date
    Mar 2010
    Posts
    88
    Missingling - interesting thought, thank you, but that's not it. My code in Form_Open can access and manipulate the variable ... and just to be sure I moved it to Form_Load instead and it made no difference.

    I don't know if it is a red herring, but the microsoft website directs you to use the three " characters, as in my example above, and I'm wondering if this is relevant (I know it doesn't work if you use only one).

    Thanks.

  4. #4
    Join Date
    Mar 2010
    Posts
    88
    Cracked it ... you need FOUR "" characters to make sure that you get a string in the form "hello world" ... so

    X.DefaultValue = """" & varname & """"

    This works!

  5. #5
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Glad you got it working!
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

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