Normal Topic Initial Value & Checkbox (Read 1040 times)
proudpoppy
Full Member
Members
***
Offline


Do What ??

Posts: 420
Location: South Carolina
Joined: Apr 7th, 2004
Initial Value & Checkbox
Mar 3rd, 2009 at 5:26pm
Print Post Print Post  
Having a problem with a checkbox, set the initial value to "N","Y","0","1","-1" nothing shows?  Sad
The checkbox is located in a subform set for table view.
  
Back to top
 
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1350
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Initial Value & Checkbox
Reply #1 - Mar 3rd, 2009 at 11:59pm
Print Post Print Post  
I don't remember why, because I've been doing it this way for a long time, but any Boolean fields in my subforms are not using initial values. I set them to an initial value via programming (in the On Form Change event). Something like the following:
if @IsBlank(Reconcile)
     Reconcile = 1
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
proudpoppy
Full Member
Members
***
Offline


Do What ??

Posts: 420
Location: South Carolina
Joined: Apr 7th, 2004
Re: Initial Value & Checkbox
Reply #2 - Mar 4th, 2009 at 12:24am
Print Post Print Post  
The why don't matter as long as it works, thanks Carl   Smiley
  
Back to top
 
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Initial Value & Checkbox
Reply #3 - Mar 4th, 2009 at 4:42am
Print Post Print Post  
Hi Carl,
On form change event, this code runs every time any element in the form changes. It will keep on firing every time enter or change data.  Let's see,  you entered the form and changed something or on Form entry programming changed something and Check box is checked automatically. Now you go and unchecked that box. You change something else in the form and checkbox will be checked again.  Well, that is what I think!!

This code should be on On Form Entry event for it to work properly and preferably with @IsNew condtional so, it does not change again when you re-enter the form in update mode, once you have manually unchecked it.  


Quote:
if @IsBlank(Reconcile)
     Reconcile = 1


Is "0" considered blank? Possibly not.
Since there are 3 possible values for check box, I usually use something like:

If Reconcile <> 1 then
       {
              Reconcile = 1
       }

The checkBox element is a little complicated one and I would like to understand the behavior of it for it to work correctly.


Bharat


« Last Edit: Mar 4th, 2009 at 5:50am by Bharat_Naik »  
Back to top
 
IP Logged
 
proudpoppy
Full Member
Members
***
Offline


Do What ??

Posts: 420
Location: South Carolina
Joined: Apr 7th, 2004
Re: Initial Value & Checkbox
Reply #4 - Mar 4th, 2009 at 2:44pm
Print Post Print Post  
I put it in the on-form entry event, haven't noticed a problem.  Wink
  
Back to top
 
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1350
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Initial Value & Checkbox
Reply #5 - Mar 5th, 2009 at 4:57pm
Print Post Print Post  
Bharat_Naik wrote on Mar 4th, 2009 at 4:42am:
Hi Carl,
On form change event, this code runs every time any element in the form changes. It will keep on firing every time enter or change data.  Let's see,  you entered the form and changed something or on Form entry programming changed something and Check box is checked automatically. Now you go and unchecked that box. You change something else in the form and checkbox will be checked again.  Well, that is what I think!!

Not so, the @IsBlank conditional will ONLY allow a change if it's blank; which means this can only happen the first time you ever make a change to the form, and never again (unless you deliberately clear the element in question).


Quote:
This code should be on On Form Entry event for it to work properly and preferably with @IsNew condtional...

This does not work for the first line item in a table-view subform. Plus, it will cause a new line item to be created every time you press the down arrow, even if all the other fields are left blank.


Quote:
Is "0" considered blank? Possibly not.

No, it's considered to have a value. @IsBlank will work with a Boolean field the way you would expect it to.


Quote:
If Reconcile <> 1 then
       {
              Reconcile = 1
       }

You wouldn't want to use this for an initial value, because it would change it to "1" no matter what state the field was in.
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1350
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Initial Value & Checkbox
Reply #6 - Mar 5th, 2009 at 4:57pm
Print Post Print Post  
proudpoppy wrote on Mar 4th, 2009 at 2:44pm:
I put it in the on-form entry event, haven't noticed a problem.  Wink

Set up that way, you should find that you will keep getting a new blank line (except for the Boolean field) with every press of the down arrow. This can be avoided by putting it in the On Form Change event.

Also, you do not want to include @IsNew in the On Form Change event in this situation, just simply @IsBlank. Because it will prevent the code from setting an initial value for the first line in the subform. (Additional lines will work, though; making appear to be working okay, at first.)

Again, simply use this in the On Form Change event, and you should be good to go.
if @IsBlank(Reconcile)
    Reconcile = 1
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Initial Value & Checkbox
Reply #7 - Mar 5th, 2009 at 5:31pm
Print Post Print Post  
Thanks Carl. My thinking was more hypothetical. Since, you have used it and it works as it is supposed to, that is the way to go. Thanks again for detailed explanation.
  
Back to top
 
IP Logged