Link to home
Start Free TrialLog in
Avatar of marian68
marian68

asked on

check boxes in forms access 2003

I have just added another 5 check boxes to my form on a new page(my form has 3 pages) but I can not see the little check in the box. Can anyone tell me why is that?
Thank you
Avatar of GRayL
GRayL
Flag of Canada image

Are you in form view or design view?
Avatar of marian68
marian68

ASKER

IN FORM VIEW
In fact I have the following codes for these check boxes on click:
Private Sub T7_Click()
If Me.T7 Then
  T7 = "KGGKHKHJKHKJHKJHKLJHKJLHKLJHKLJHKJH"
Else
  T7 = ""
End If
End Sub
Without this code no problem but as soon as I put this code I can not any more see the little check in form view.
Thank you
ASKER CERTIFIED SOLUTION
Avatar of GRayL
GRayL
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
yes I am trying to make this label a string for the checked boxes
Then change your code from:

Private Sub T7_Click()
If Me.T7 Then
  T7 = "KGGKHKHJKHKJHKJHKLJHKJLHKLJHKLJHKJH"
Else
  T7 = ""
End If
End Sub
to:

Private Sub T7_Click()
If Me.T7 Then
  Me.Label0.Caption = "KGGKHKHJKHKJHKJHKLJHKJLHKLJHKLJHKJH"
Else
  Me.Label0.Caption = ""
End If
End Sub

Change Label0 above to your actual label name.
The name of the label is different from the name of the check box.
For another check boxes I have the following code and it works very well even if there is a string in the code
Private Sub O42_Click()
If Me.O42 Then
  O42 = "yes"
Else
  O42 = 0
End If
End Sub
Thank you
VBA will convert a 'Yes' to a value of -1.  It cannot do anything with "KGGKHKHJKHKJHKJHKLJHKJLHKLJHKLJHKJH" - besides which I thought you said you wanted to display that string the the checkbox label?
I made the changes and I am receveing -1 for the box checked.
Thank you
No I want to display that string in the table. We will continue tomorrow, I have to go.
Thank you
hi I am back
It is interesting that even if I can not see the little check when I enter a new record and I check the boxes(without seeing the little check) I can find in the table the string in my code.
Thank you
Are you sure that there is no possibility to store a string when I check a check box?
Thank you
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Time for a recap.  You have a table and a form.  The form is bound to the table?  When you click a checkbox on the form the code behind the checkbox inserts a new record in the table and provides one of the fields with a string that is preset in the code?  At the same time it loads the checkbox label caption with that same string?  
Yes Grayl it is correct.
Thank you
For DokieBoy: I don't understand. If I set the visible property to No how could the users check the check box.
Thank you
marian68:  I have a form named frmLbxTest on which I have a check box named Check2 which has a label named Label3.  The form is bound to a table name tblMovements in which I use the check box to insert a new record and update the field named Program.  I inserted this code in the click event of Check2:

Private Sub Check2_Click()
  DoCmd.GoToRecord , "frmLbxTest", acNewRec
  Me!Program = "My Test"
  Me!Label3.Caption = "My Test"
  'DoCmd.Close acForm, "frmLbxTest", acSaveYes
  DoCmd.Save , "frmLbxTest"
End Sub

This does precisely what I said in my recap above which you said was correct.
I am sorry GRayl, I think I made a mistake. I will rephrase the problem using your text:
 I have a table and a form.  The form is bound to the table?  When I click a checkbox on the form I would like the code behind the checkbox inserts a string in the table in the field which has the same name with the check box.
The problem is I can not see the little check in the little box.
If it is easier for you, another way to solve the problem would be to build a list box where I could choose 2 or 3 items from a single list. Can you give me the VBA code to do that and the problem is solved. In Access 2007 this issue has been solved but in access 2003 I need a VBA code.
Thank you
Are you talking 'the same name with the check box.' or 'the same name as the label of the text box.'  In addition, is this to replace the field with the same name on the selected record, or on a new record?  BTW, it is bad naming practice to have a control with the same name as the field to which it it bound.  BTW,  I only introduced the ListBox because that form just happened to have a checkbox.  Do you mean select two or three items (multi-select property of the list box)  or select one of two or three items?  

It might be easier to pare you mdb down to the minimum required to support the question, do a Compact & Repair, and upload the mdb here using File below.
"Do you mean select two or three items (multi-select property of the list box)  or select one of two or three items?"
I mean 2 or 3 items from a list of 5 items - multi-select property of the list box.
Yes like I said, the check box has the same name as the field name in the table.
 I didn't know that "it is bad naming practice to have a control with the same name as the field to which it it bound".
Thank you
We are on frmTest, bound to tblTest. We have a list box  ListItems with a string in 5 rows, "First"," Second", "Third", "Fourth", and "Fifth" - "First", "Third", and "Fifth" are selected.  check box checkA is clicked.  in tbTest the is a field named fldA - you are on the 39th record of 42 records.  What do you want to happen?

BTW, when troubleshooting, how does one know whether the field, or the control is the source of the problem if they have the same name?
GRayl, I have no idea you are talking about?
In the field in my table after the selection of 2 items I will have a concatenation of the 2 text items selected in my list box.
Thank you
And what happens to the label of the check box?
Try this code in the Click event of the check box.

Private Sub chkTest_Click()
  'We are on frmTest, bound to tblTest. We have a list box  ListItems with a string in 5 rows, _
  "First"," Second", "Third", "Fourth", and "Fifth" - "First", "Third", and "Fifth" are selected. _
  check box checkA is clicked.  in tbTest the is a field named fldA - you are on the _
  39th record of 42 records.
  Dim strItems As String, lbox As Control, arr As Variant
  Set arr = Me!ListItems.ItemsSelected
  DoCmd.GoToRecord , "frmTest", acNewRec
  Set lbox = Me.ListItems
  Set arr = Me!ListItems.ItemsSelected
  strItems = lbox.ItemData(arr(0)) & ", " & lbox.ItemData(arr(1))
  Me!Program = strItems
  Me!lblTest.Caption = "My Test"
  'DoCmd.Close acForm, "frmLbxTest", acSaveYes
 ' DoCmd.Save , "frmTest"
 Me.Refresh
 Set arr = Nothing: Set lbox = Nothing
End Sub
For GRayl:
Maybe my english is too bad and created some misunderstanding but I don't need a check box and a list box in the same time.
What I need is only to be able to store a string in the table using a check box, the string being the same with the content of the label of the check box.
I said that if this thing is not possible instead of these check boxes I can build a list box with all possibilities (5 check boxes = 5 strings in my list box) with the strings in question where to have the possibility to select more than 1 string.
Thank you
Ahhhh, I get it now.  :)  

The caption of the label for check box 1 is set to "some_text"
The caption of the label for check box 2 is set to "some_other_text"
so on and so forth.....

If a check box is checked (set to true) you want the label caption to be stored in a table.

If that is the case, then I think you should do the following;

1.  Use a List Box with multi select
2. Trigger the update of the selections made to your table using a button
3. Store the data in a separate table along with the PK from the table you are currently using so you
    can reference and view the data easily.