refreshing a checkbox

  • Thread starter Thread starter Chad
  • Start date Start date
C

Chad

I posted this in a google google group and havent had any
luck as of yet. Maybe you guys can help me.

I have a list box that gets it data from a query (we can
call it listbox1)I also have a checkbox that returns
information depending on which records are selected in
Listbox1. When I click on the record in runtime,
everything runs great, but I need to be able to perform
this action in code. I am able to selct different records
in the Listbox1 using Listbox1.Selected(intIndex), but
when I do this the checkbox is not refreshed. I am
fairly new to VBA so I am not sure about what code I
should use to accomplish this. I have already tried to
use chkRecord.Requery but that doesn't work. Any help
would be greatly appreciated.

Thanks in advance,
Chad

**The only reply I have gotten from the google group is
to try chkRecord.Recalc. When I use that it says that
the object doesn't support that property or method.**
 
Wayne,
THanks a lot for replying to my post I have been having
many headaches trying to figure out a way to get around
this. I am not sure that running the event will help too
much but then again I am not that literate in VBA.
I have thought of 2 different ways to maybe get around
this and please let ma know if these are valid, they are
both similar.

1. Is there a way to autmate pressing the next record
button of a record selector. If I was able to do that
then both the next record in the list box will be
selected and the Record checkbox will be updated.

2. Right now, as you know, I am able to go through each
record for the list box by using
ListBox1.Selected(intIndex). Is there an equivalant to
this for a check box, so even though I have to do them
seperatedly in code I can have the records change in both
listbox and the check box.

Thanks again,
Chad
-----Original Message-----
You will probably need to tell the check box to have the value you want under the
conditions set up by your code.

Example:
Me.chkMyCheckbox = False

You are correct, updating through code frequently
doesn't fire the events that actually
clicking on the item will fire. Another possible options (it depends on how you have
things set up) is to tell the event code to run once you
have set the items in the listbox
through code.

Example:
listbox1_Click

This assumes that the code is on the same form as the
listbox. If not and this is what you
 
A check box doesn't have an index number because it doesn't hold multiple values at one
time, it is either True or False. If it is set for Triple State then add Null to the
possible list. Simply setting the value of the checkbox is how you would set it. Now, if
you name your checkboxes sequentially, you can use a loop to go through them.

Example:
chkCheckbox1, chkCheckbox2

For i = 1 to 2
Me.Controls("chkCheckbox" & i) = False
Next i


Yes, you can move from one record to another in code.

Example:
If Not Me.Recordset.EOF Then
Me.Recordset.MoveNext
End If

EOF stands for End Of File, you don't want to move to the next record if you're at the
end.
 
Wayne,
THanks for your help. Moving to the next record does
exactly what I needed.
Chad
-----Original Message-----
A check box doesn't have an index number because it
doesn't hold multiple values at one
time, it is either True or False. If it is set for
Triple State then add Null to the
possible list. Simply setting the value of the checkbox
is how you would set it. Now, if
you name your checkboxes sequentially, you can use a loop to go through them.

Example:
chkCheckbox1, chkCheckbox2

For i = 1 to 2
Me.Controls("chkCheckbox" & i) = False
Next i


Yes, you can move from one record to another in code.

Example:
If Not Me.Recordset.EOF Then
Me.Recordset.MoveNext
End If

EOF stands for End Of File, you don't want to move to
the next record if you're at the
 
Wayne,
I promise this is my last question for you. Thank you
for your patience. In moving to the next record with the
code Me.Recordset.MoveNext, how would I switch Me to the
name of the form that I am using. I tried
Forms!frmResults!subfrmSCResults.Recordsset.MoveNext but
it ways that the object doesnt support that property or
method. The reason I am asking is because I was thinking
about putting the code in a seperate module and calling
on it when I needed it.

THanks again.
Chad
-----Original Message-----
A check box doesn't have an index number because it
doesn't hold multiple values at one
time, it is either True or False. If it is set for
Triple State then add Null to the
possible list. Simply setting the value of the checkbox
is how you would set it. Now, if
you name your checkboxes sequentially, you can use a loop to go through them.

Example:
chkCheckbox1, chkCheckbox2

For i = 1 to 2
Me.Controls("chkCheckbox" & i) = False
Next i


Yes, you can move from one record to another in code.

Example:
If Not Me.Recordset.EOF Then
Me.Recordset.MoveNext
End If

EOF stands for End Of File, you don't want to move to
the next record if you're at the
 
Me is shorthand for the form that the code is running on. To refer to another form you
need to use, as you indicated, Forms!FormName. To refer to a subform on a form, you need
to refer to the control on the main form that holds the subform.

Example:
Forms!frmResults!NameOfSubformControl.Form.Recordset.MoveNext
(you also had a typo, only one "s" in recordset)

If the form running the code is frmResults you could shorten the above:
Me!NameOfSubformControl.Form.Recordset.MoveNext

To get the name of the subform control, open the main form in design mode. Open the
Properties sheet if it isn't already. Click on the subform ONE time. The Properties sheet
should show the name of the subform control. If you click twice, you'll be in the subform
and the Properties sheet will show the name of the form, not the control holding it.
 
Back
Top