Full Version: Check Boxes
UtterAccess Forums > Microsoft® Access > Access Forms
nalym
Is there anyway of storing a value instead of a -1 when a check bow is checked. For instance when a user check the box, I want for Hard Copy to be displayed in the field. Thanks!!
dashiellx2000
I'm assuming you only want "Hard Copy" to appear if the check box is checked.
On the check box's after update property:
If Me.CheckBoxName = -1 Then
Me.[TextBoxName] = "Hard Copy"
Else
Me.[TextBoxName] = ""
End If
HTH.
michaela4
Why not place a text box next to the check box and when the check box is checked have it hold the "hard copy"?
The text box source can have this
=iif([checkbox name]=-1,"Hard copy"," ")
The last part of the statement will blank out the textbox if the checkbox is unchecked.
HTH
Michael
nalym
Sorry I didn't explain that right. I just want for the Table to capture Hard Copy instead of -1. I don't have a text box anywhere that needs the value. SOrry for the misunderstanding
ScottGem
Let me propose this differently. What I think you really want is to be able to display the phrase "Hard Copy" if the field evaluates to True. You can do that eaisly using the expression:
IIF([fieldname],"HardCopy","othertext")
nalym
where would that if statement go then?
It would be:
=IIF([MailType],"HardCopy","Email")
for a Table with Field MailType
ScottGem
It would go ANY place you want to display the text instead of a checkbox.
I'm assuming here that MailType is a Yes/No field. But what if it can have three values? Hard Copy, E-mail, Fax What is the label where the user checks off the checkbox?
nalym
I have a form the user can either have their stuff to be Emailed or Mailed to an address(Hard Copy)
The check box has a label next to it "Mail hard copy". So if it is checked then they will get it mailed to an address but if it is left blank then it is emailed. this is because we would preferably email all of them...the hard copy is just in case some doesn't have a computer, or email. I included in the table MailType so that when we pull all of the users info we can pull by Email or Hard Copy. I know I could easily put a drop down with Hard Copy and Email as the values, but I would rather do it with a check box. Does that kinda make it easier?
ScottGem
That all makese sense. If you want to display the text on the reports I would do it in the query:
ail By: IIF([MailType],"HardCopy","Email")
For you use the expression:
=IIF([MailType],"HardCopy","Email")
Has the controlsource of a control on a form or report.
nalym
I guess I don't understand what you are saying by IIF([MailType]
This is because I normally use an IF statement as If[something]=something, true value, false value
so I guesss my question is what is your something in that expression
Because that check box will still store a -1 of a null value correct?
ScottGem
When you have a Yes/No or Boolean field you do not need to specify True or False
IF([MailType],True Condition. False Condition) evaluates Mail Type as True. If you want to test for false you could use:
IIF(NOT [MailType]...)
If you feel more comfortable using:
IIF([MailType] = -1,...)
then go ahead
nalym
ok I unserstand that. So then if I want the table to say Hard Copy and not -1 and Email and not 0 then where should I put that statement...in the table - MailType field's default value? I don't want -1 and null to be stored anywhere
nalym
I have a question...not access related. Why is it that you are always the one who answers all of my questions? Are you always on here helping people? That's cool...I appreciate it a lot!
ScottGem
I told you were to put it. NOT in the table. You will continue to store -1 or 0. You use that expression where you want to DISPLAY the text
ScottGem
I'm not always on, but work is slow right now so I just have extra time to monitor the site.
nalym
well then that is what i did before. I used that same IF statement...I just made it equal to -1.
I used it for a FORM1 with a drop down box that uses a QUERY1 to fill the drop down. The QUERY1 is where I put the If statement. That all worked fine. The problem came when I went to create a REPORT1 where it is based off of a QUERY2 where the MailType has criteria of what is chosen on the form.
I am having to chnge it from -1 and 0 to Hard Copy and Email for FORM1 through QUERY1 then for a report to run I am having to convert what is chosen on FORM1 (i.e. Email) back to a 0 so that the QUERY2 knows what to pull and then again on the REPORT1 display the 0 as Email again.
I got it all working up until the QUERY2 and REPORT1
ScottGem
If you add a column like this:
ail By: IIF([MailType],"HardCopy","Email")
to ANY query, then you will have your conversion. You can then use that column in your report instead of the actual value.
nalym
I have it working so that on the form I select a date and then I can select a MailType depending on which dates have which ones entered. Then when I run the report, the report is being populated from a query that has the main table with all info and then also the query I used to get the mail type. I am using MailBy to display the the Mail Type preferred but when I select Email or Hard Copy from the form all records are returned.
ScottGem
How are you doing the selecting? We haven't changed the table at all. The table still uses the Boolean (Yes/No) field. So, if you are looking to filter, you need to use True or False.
nalym
How do I select MailBy as true or false if the value coming back from the form is Email or Hard Copy. Because when the user selects on the form the MailBy it is a value(Email or Hard Copy) that is where I have the problem because I only want to records on a particular date(sleceted on that form) and with a particulay MailType -- Email or Hard Copy. But I think when I put that MailBy in the select query it doesn't know what the value Email or Hard Copy is. I tried to convert it back to -1 and null (yes and no) but I don't think I did it correctly.
Oput this in the criteria
IIf([Forms]![SelectDate]![MailType]="Hard Copy","-1"," ")
ScottGem
You don't do it on Mail By, set your criteria for the actual field not the calculated one.
nalym
then how will it know to only sort by the value choosen by the user (Email or Hard Copy) on the form
ScottGem
Let me try to explain this. You are mixing apples and oranges here. A database has three functions: data entry, data storage, data retrieval. Those three functions are somewhat separate. They should be considered separately though there may be overlap.
For ease of data entry, you decided to have the user just check off a box to indicate they want hardcopy instead of an e-mail. This is fine and a good design tool. For ease of design you then decided to make the field that stored this data a Yes/No field. While you could have done it differently, this was an obvious decision once you made the data entry decision. Now you have made a decision that when you DISPLAY the value on some reports you want to display a description of the choice instead of a checkbox. Again there is nothing wrong in this, its good design in many cases. But you need to think of each item separately.
So when you want to FILTER your data you should use the ACTUAL field that is storing the data. So you add the Yes/No field to your query and set the criteria to True (or False). To display the text you use the MailBy expression I gave you.
nalym
With Yes/No the Yes is stored as -1, what is the no stored as? " " or null ?????
nalym
With Yes/No the Yes is stored as -1, what is the no stored as? " " or null ?????
dashiellx2000
In the query you can use True/False, Yes/No or -1/0
ScottGem
0, False or No. Could also be Null if not nothing was selected. If Nulls are possible then if you want all Hardcopy set the criteria to Yes, True or -1. If you want all E-mails set the crtieria to Not True.
Personally, I wouldn't allow Nulls in this case. I woudl set the default value to No. If you want to make sure there are no Nulls then run an Upodate query setting hte value to No if Null.
nalym
ok I think i got it...i used this in the criteria
IIf([Forms]![SelectDate]![MailType]="HardCopy",True,False)
for the input info populating the report and it worked
thank you!!
hope this can help someone else if they need it
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.