I work in a project with 12 chekbox(12 monthname) and a textbox. when I check a box a month
name like "january" show in textbox. when I check another checkbox "February" show in that
textbox after january. like "January February" as like same 12 checkbox. but when I uncheck
any checkbox the textbox become blink. coz I write code
if check1.value = 1 then
text1.text = "january"
else
text1.text = ""
end if
if check1.value = 1 and check2.value = 1 then
text1.text = "january February"
end if
I write it with a module. but I want when I uncheck a checkbox it will erase that monthname
others monthname will show in textbox. if there is any other way to do this like listbox,
or other then help me please or help me with this project.

hi. you're transferring all the data to text1 and you also clear it when you uncheck a button.
so its better if you uncheck a checkbox, just clear the text1 then just get all the value of checkboxes then place it on the textbox but you have do it in chronological order.you start from january up todecember.

you can try this. just call this in the click event of every checkbox

Sub check()
Text1.Text = ""
If Check1.Value = 1 Then
    Text1.Text = "January"
End If
If Check2.Value = 1 Then
    Text1.Text = Text1.Text & " February"
End If

If Check3.Value = 1 Then
    Text1.Text = Text1.Text & " March"
End If
End Sub

Hi,

An Easier way out is Control arrays..
In a New Form, Place a CheckBox Control on the from from the tool box, copy and Paste, VB will ask if you want to create control array, say yes, add 12 Times,
all of them will have a same name, but Differ in Index, Change Captions accordingly.. Remove Check Box with Index=0..
and in Click event of Check box, write this code

Text1.Text = MonthName(Index)

Note : all CheckBoxes will be having same Event Procedure....

Regards
Veena

Augxis you code do well. thank you.
dear veena
>>Change Captions accordingly.. Remove Check Box with Index=0..
this line I don't understand.
>>Note : all CheckBoxes will be having same Event Procedure....
there are no other checbox. only show check1

hi...

use this code...

Private Sub Check1_Click()
Call check
End Sub

Private Sub Check2_Click()
Call check
End Sub

Sub check()
If Check1.Value = 1 And Check2.Value = 1 Then
Text1.Text = "january February"
ElseIf Check1.Value = 1 And Check2.Value = 0 Then
Text1.Text = "january"
ElseIf Check1.Value = 0 And Check2.Value = 1 Then
Text1.Text = "February"
Else
Text1.Text = ""
End If
End Sub

Regards
Anandh

Dear Veena
I am interest about your code. can you help me please.....more......

taher

I work in a project with 12 chekbox(12 monthname) and a textbox. when I check a box a month
name like "january" show in textbox. when I check another checkbox "February" show in that
textbox after january. like "January February" as like same 12 checkbox. but when I uncheck
any checkbox the textbox become blink. coz I write code
if check1.value = 1 then
text1.text = "january"
else
text1.text = ""
end if
if check1.value = 1 and check2.value = 1 then
text1.text = "january February"
end if
I write it with a module. but I want when I uncheck a checkbox it will erase that monthname
others monthname will show in textbox. if there is any other way to do this like listbox,
or other then help me please or help me with this project.

hello; this is probably a bit of an overkill; but when i was thinking about it, then testing it; i didn't actually write the months in the checkboxes. so if you were going to actually list the month name as the check box caption; i guess you could get the month name from there...

as i said, i did it a little differently...

Private x As Integer
Private fakeDate As Long

Private Sub chkMonth_Click(Index As Integer)
 txtMonths.Text = ""
 For x = 1 To 12
  If chkMonth(x).Value = vbChecked Then
   fakeDate = DateSerial(1, x, 1)
   txtMonths = txtMonths & Format$(fakeDate, "MMMM ")
   MsgBox x
  End If
 Next x
End Sub

the variable 'fake date' is just that, it's a fake date... it always sets the day to 1, always sets the year to 1, could make it set to the current date, but there's not really much point and since i don't currently have access to a vb help file or remember the date functions off hand, this is as best i can do.

this works by looping through a checkbox control array; by default a control array starts at 0 but i felt that setting it to 1 would be easier to show. Using a for next loop you can check the values of each check box; you can then get the month name from the system by creating a fake date with that x value as the month and using the format function to return the month name (with a space at the end...). then add it to the text box.

if you had labled the check boxes, you could instead loop like this

For x = 1 to 12
if chkMonth(x).value = vbChecked then 
 txtMonths.text = txtMonths.text & chkMonth(x).caption & " "
end if
Next x

hope that helps...

Private x As Integer
Private fakeDate As Long

Private Sub chkMonth_Click(Index As Integer)
 txtMonths.Text = ""
 For x = 1 To 12
  If chkMonth(x).Value = vbChecked Then
   fakeDate = DateSerial(1, x, 1)
   txtMonths = txtMonths & Format$(fakeDate, "MMMM ")
   MsgBox x
  End If
 Next x
End Sub

please ignore the

MsgBox x

listed within the code...

(edit)Sorry, i didn't notice the edit this post button until just now...(/edit)

This question has already been answered. Start a new discussion instead.