Results 1 to 6 of 6
  1. #1
    2 Star Lounger
    Join Date
    Nov 2004
    Location
    London, United Kingdom
    Posts
    152
    Thanks
    0
    Thanked 0 Times in 0 Posts

    setting default value (2000)

    Hi,

    I have a simple form, with a combo box with a value list. The user can choose 1 of 3 values. When the user chooses a value, I want that value to become the default value for that combo box for allnew records. The code I have runs and then the new record displays
    #Name?
    in the combo box.

    This is what I've got
    Private Sub cboTransactionType_AfterUpdate()
    cboTransactionType.DefaultValue = cboTransactionType.Value
    End Sub

    Any advice would be very appreciated.

    Amanda

  2. #2
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: setting default value (2000)

    Hi Amanda,

    The code works for me. Usually if you get a #Name error, it signifies a error in spelling of a control name, or function argument! Just check spelling of the controls. It should sort it out!
    Regards,
    Rudi

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: setting default value (2000)

    What is the data type? If it is text, you need quotes around the value:

    cboTransactionType.DefaultValue = Chr(34) & cboTransactionType.Value & Chr(34)

    Chr(34) is the double quote character ".

  4. #4
    2 Star Lounger
    Join Date
    Nov 2004
    Location
    London, United Kingdom
    Posts
    152
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: setting default value (2000)

    Hans,

    Thanks, that has sorted it. Makes sense too.

    Amanda

  5. #5
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: setting default value (2000)

    Just to expand on Hans' response, which undoubtedly will solve your problem, the reason you need to encase it in quotes is because you want Access to treat it as a string and not a function. For example, let's suppose your transaction type was "Credit". Note the difference in what gets put in the DefaultValue.

    Your code: Credit
    Hans' code: "Credit"

    In your code, Access sees what it thinks is the Credit function, whereas Han's code allows it to see that it is a text string.

    Similarly, if your field was a date/time field, you would need to encase it between 2 # signs, like this:
    TransactionDate.DefaultValue = "#" & TransactionDate.Value & "#"
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  6. #6
    2 Star Lounger
    Join Date
    Nov 2004
    Location
    London, United Kingdom
    Posts
    152
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: setting default value (2000)

    thanks Mark - makes sense once it has been pointed out!

Posting Permissions

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