Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2012
    Posts
    4

    Unanswered: Unmark check box based on a text field

    Greetings,

    I have a checkbox defaulted to being check. Once a person enters in a date in a text box then the checkbox should be unchecked. Sometimes, the checkbox can be unchecked if the text box is blank. So what I want to do is once a date is entered then the checkbox is unchecked but I do not want the check box to be checked if the date is later removed.

    I tried the following code:

    checkbox_xyz = not isnull(date_textbox)

    This checks and unchecks the checkbox based on the textbox status.

    I also tried:

    if not isnull(date_textbox) then checkbox_xyz = 0
    if not isnull(date_textbox) then checkbox_xyz = false

    None of the above worked. Thanks for any guidance.

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    so to paraphrase
    the checkbox is unbound (its not set directly by anything in the database)
    if someone has entered a date into a control, which is bound to a column in the database) then the checkbox should be unchecked....

    create a function whcihc sets the value of the checkbox
    eg
    Code:
    Private function SetCheckbox() as boolean
    'returns a boolean value to set the checkbox
    'will return
    ' true if the checkbox should be set (ie the control doesnt' contain a valid date)
    ' false if control does contain a valid date
    if isdate(mycolumn) then
      SetCheckbox = false
    else
      SetCheckbox = true
    endif
    end function
    ..or a shortform.. does the same thinbg just takes writes it as a single line of code
    Code:
    Private function SetCheckbox() as boolean
    'if the value of mycolumn is valid date then return true, if it is a date return false
    SetCheckbox = NOT isdate(mycolumn)  
    end function
    then you need to decide where to set this checkbox
    ..personally I would want to set it in
    ..the forms on current event (whenever the current row/record changes)
    ..the controls on change event
    ..the controls on lost focus event

    mycheckboxcontrol.value = setcheckbox()
    that assumes you have
    a column/control called mycolumn which will store the date of whatever
    a checkbox control called mycheckboxcontrol
    replace thoe above with values that are appropriate to your application design
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Aug 2012
    Posts
    4
    Thank you for your response. Correct me if I am reading the code wrong but it would seem the code will check the box if the date is valid and uncheck the box if the date is blank or invalid. This appears to do the same as the code:

    checkbox_xyz = not isnull(date_textbox)

    The problem is I do not want the box to be checked if the date text is blank. I only want the check box to be unchecked if a valid date is in the date text field.

    Thank you.

  4. #4
    Join Date
    Aug 2012
    Posts
    4
    Mess around and got the solution.

    If Not isDate(date_textbox) then checkbox_xyz = 0

    The isDate was the key. Thanks healdem!

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    well I'd suggest you try the two versions out
    try the isNULL version
    try the isdate version
    and/or read the help files or do a search on what the isNULL and isDate functions do
    I'd rather be riding on the Tiger 800 or the Norton

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    so is the checkbox set in all conditions that you require
    I'd rather be riding on the Tiger 800 or the Norton

  7. #7
    Join Date
    Aug 2012
    Posts
    4
    The check box is set for true as default for each new record. Once a date is entered then the checkbox is false. Sometimes the date is removed but the checkbox does not need to be rechecked. The isDate portion allowed me to do this. The isNull was not the appropriate function.

    Thanks again!

Posting Permissions

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