Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2007
    Posts
    6

    Unanswered: Default Value For A Certain Field

    Hi All, i am new to access and got a real simple question

    I have a text box which requires user to enter some numbers(e.g : -4.3, -3.2)

    However i do not want the user to key in the "-" value, but it will be automatically displayed in my table.

    Tried playing around with the default value property but was unable to get anything out of it.

    TY for any help rendered.^_^

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    So this value will *always* be negative?

    I assume you're using bound forms? If so, you have very little say over what the user gets to see. Go unbound for more control (unbound means you have to write your own updates, inserts, delete statement etc as appropriate - it's more work but worth it imo).

    However, one solution I can think of would be to hide the offending textbox, creating a second one and make it pul the value from the bound textbox multiplied by -1.. Remember you'll have to write the value back to the original box when it's updated too!
    George
    Home | Blog

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    seriously don't go there

    always get the user to put in a minus sign, it just doesn't make sense in my mind to remove it, precisely because the value has a meaning. if for no other reason consistency... everywhere else this value is used its known as -x, if you start allowing propel to use it as x and then add back the - you are making (light) work for yourself. You'd be amazed how quickly somebody can slam in data into a db using the key pad... and the - sign is top right.

    however if you must persist then I'd suggest some code behind the controls on lost focus, and before update events.. call a function say called ForceNegative, say
    Code:
    mycontrolname.value =  ForceNegative(csng(mycontrolname))
    Code:
    private function ForceNegative(sngvalue as single) as single
    ForceNegative= -1*(abs(sngvalue))
    end function
    I'd also be tempted to put a validation rule in the table design for this column which constrained the value to be negative, or in the range that is appropriate for this item.

    the reason for putting the function call in two (or more places), is that events fire in Access at various times.

    so...
    placing it in the lost focus event, will force the function to fire when the control looses the focus (so it shows the user what value is in the control right now)
    placing it in the before validation makes sure the data is correct before committing data to the db
    ... its possible to change a value in a control and force a before update without going through the on lost focus.

    you could change the function to check if its negative already, eg
    Code:
    if ForceNegative= -1*(sngvalue) then
      ForceNegative= -1*(abs(sngvalue)) ' convert the number to negative
    else 'the value is already negative.. don't do anything
      ForceNegative= sngvalue
    endif

Posting Permissions

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