togglebutton value help

D

dchendrickson

I am using Access2002/XP Pro and programming primarily
with ADO structures.

I have a form with several unbound togglebuttons. A
combobox on the form changes the underlying record for
the form. As the record changes, I need to save and
restore the state of the togglebuttons.

As the form changes records, my code cycles through all
the controls on the form, finds the togglebuttons,
converts their state to a string, then concatenates all
the strings into a ";" delimited string saved with the
record.

There is matching code that reads the string for the new
record, splits it up, then cycles through the
togglebuttons and sets their state accordingly.

This was working for a while, but now I am running into a
bug and not sure of the cause.

As the code cycles through and reads the state of the
togglebuttons, it returns either a 0 or a -1. So my state
string looks like:

0;0;0;0;0;-1;-1;0;0;0;-1;0;-1;0.........

But there are a few togglebuttons that are returning TRUE
instead of -1. So my state string is now looking like:

0;0;0;0;0;True;-1;0;0;0;True;0;-1;0.........

This causes a type mismatch when I try to read the string
the next time the record is current.

I have looked at the properties of the offending toggles,
but can't see a setting that is different. (When the
toggles were originally created, I made the first one,
the used copy-paste for the rest).

Below is my code for reading and saving the state string.
Any ideas why some the return of some toggles is
different? Thanks for your help.

-dc



Public Function ConcatenateState(frm As Form, strState As
String)
On Error GoTo Err_ConcatenateState

'-----
'This Function reads the value (state) of each toggle
button in the form and saves it to an
'array. The values in the array are then concatenated
into a semicolon delimited string.
'-----

Dim ctl As Control
Dim astrState() As String
Dim intCount As Integer
Dim intSize As Integer

Let strState = ""
Let intCount = 0
Let intSize = SizeOfArray(frm)

ReDim astrState(intSize)

For Each ctl In frm.Controls
If ctl.ControlType = acToggleButton Then
Let astrState(intCount) = CStr(Nz(ctl.Value, "0"))
Let intCount = intCount + 1
End If
Next ctl

Let strState = Join(astrState, ";")

Exit_ConcatenateState:
Exit Function

Err_ConcatenateState:
.....error handler code....
End Function
 
A

Assaf

DC:

If all you want to do is make sure you get only -1 and not TRUE's, you can
try using Replace:

Let strState = Join(astrState, ";")
Let strState = Replace(strState, "True", "-1")

- Assaf
 
D

dchendrickson

Assaf,

Thanks for the suggestion. That should fix it fine. But I
am still not sure why it should need fixing in the first
place????

I also put some extra code in the routine that reads and
splits the string. I basically run the returned value
through a couple of type conversions to ensure it ends up
the correct type.

..... = CInt(CBool(str))


-dc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top