Checkbox question

Jerome

Registered User.
Local time
Today, 08:32
Joined
Jul 21, 2009
Messages
77
Hello,

I want to use a checkbox to let a uses choose between "yes" and "no"

In my data table I would like to display this as something else. For example: Coffee, Tea.

I try to accomplish this the following way:

I have a checkbox and a hidden textbox (source control is linked to the right column in the table).

When the checkbox is clicked the following code runs:

Code:
Private Sub Check32_Click()

If Me.Check32.Value = True Then
Me.TxtXiHidden = "Coffee"
End If

If Me.Check32.Value = False Then
Me.TxtXiHidden = "Tea"
End If

End Sub

The only problem is that this works one time (true). When I try to click it again is does not work. When I remove the control source (so it's unlinked) it works?

Is this the "normal" approach to accomplish this? What a IO doing wrong?

Thanks in advance.
 
Last edited:
In my data table I would like to display this as something else ....
I have a checkbox and a hidden textbox (source control is linked to [a field]).

This is where you are going of track. It is pretty much opposite to how it is done.

Tables store data. Forms and Reports display it. You should not be recording the string "Coffee" in your table.

One more usual way is to have a field called Coffee with a checkbox field type. It is bound to a checkbox on the form. Tick coffee on the form and coffee gets ticked on the table. This way you must have one field for each drink.

There are other ways where all the drinks are stored in a separate table so you don't have to add a new field every time a new drink is added.
But you probably don't need that.
 
Another alternative is to create an option group. This allows the user to select either Tea or Coffee, not both. Both tea and coffee will have an assigned value this could be 0,-1 or 1,2 then bind this value in the field in your table.

David
 
Ok, the problem is that I want to use this data to display in a report. In this report I want to display Coffee or Tea and not 1 or 2. Maybe I have to search for another solution.
 
Thant not a problem.

You can do a couple of things

1. In your report for the control that is displaying the outcome of the field the control source would be IIf([Beverage]=1,"Coffee","Tea")

2. Write a function that translates the code into the description such as

Code:
Public Function Beverage(AnyCode as Integer) As String

Select Case Anycode
    Case 1:Beverage = "Coffee"
    Case 2:Beverage = "Tea"
    Case Else:Beverage = "Neither"
End Select

End Function

3. There is also the Switch() Function that you could explore

David
 
Ok, this works great :). I use a listbox (in a searchform) to populate data from the data table. Is there a way to do the same in the listbox?

Because now the 0 and -1 values are also displayed in the listbox.

Thanks.
 
Change your list box option, bring up the properties tab for your list box

Ensure that the Column Count option has the same number of columns as the query used to generate the list box.

Also then you can hid the columns not used by changing there size in the Column Widths Option, separate your values with a , ie 0,2,0 would display only the center column at 2cm

Hope this helps :)
 
Not clear what you are asking but maybe something like this would be the follow up to DCrake's last post.

In your listbox properties:

Row Source: 1;Coffee;2;Tea ....etc
RowSourceType:List
Bound Column:1

Column Count: 2
Column Widths: 0cm;3cm

Or use another table with the drinkcode and drinkname to populate the Listbox using a Table/Query Row source. (This is usually a better way because drinks can be added to the table through a foem instead of editing the Row Source list.

Either technique will display the word but store the number. (The 0cm width supresses the first column.)

I suspect you may currently be using Inherit Value List: Yes which takes the RowSource form the data table itself rather than the RowSource entry. This can't be done using drinkcodes. Set it to No.

However you appear to be storing True (-1) and False(0) from a checkbox rather than a drinkcode. I think we are all working on different strategies. You are probably thoroughly confused at this point.
 

Users who are viewing this thread

Back
Top Bottom