if nothing else, the shows that not counting beyond one really can be beyond one...
my database (ss7) has a field (fldRelevant) which is supposed to mark the relevance of something. it is a field which holds a boolean/bit value (1 for relevant or 0 for irrelevant).
my app could simply have a chkbox which is bound to that field (checked (1) for relevance or unchecked (0) for irrelevance) - but i have decided not to. i prefer to have a chkbox which is checked (1) if the field shows irrelevance or unchecked (0) if the field shows relevance; i.e. the chkbox shows the opposite status to the value in the db.
this is the code i have which updates the field when i mousedown on the chkbox to change its state. the purpose of this code is to put the opposite value into the field to which it is unbound (if you catch my meaning):
aside: bear in mind that vb shows true as -1 (rather than +1), so although the value of recordset!fldRelevant will be 0 when the db's value is 0, it will be -1 when the db's value is +1. to get around this, i multiply the recordset's value by -1 to reverse the sign of a 1 (of either type) before subtracting one to turn 1 into 0 or 0 into -1 for the recordset (ado deals with turning this -1 back into 1 for the db):
when i navigate to a record, i want to do the reverse, that is make the chkbox checked (1) when the db's value is 0 and make the chkbox unchecked (0) when the db's value is 1. again, the value of recordset!fldRelevant will be -1 (true) when the db value is +1. this code adds 1 to the recordset's value, turning 0 into a 1 or -1 into a 0 to arrive at the chkbox's value:
(the event i use is mousedown rather than click because another click event would be raised when the value of the chkbox is changed)
the strange thing is that when i check/uncheck the chkbox for the first time having reached a record, the check appears/disappears as intended but instantly returns to its state before the mousedown - an effect opposite to that intended. however, subsequent checks/unchecks on the chkbox (whilst still on that record) operate as intended - the checked status of the box is reversed and the appropriate value goes into the db. this "first time" behaviour is the bit i can't work out.
to make matters worse, this strange behaviour exhibits itself only at run-time. it behaves as intended when i step through.
does anyone have a clue what is going on?
my database (ss7) has a field (fldRelevant) which is supposed to mark the relevance of something. it is a field which holds a boolean/bit value (1 for relevant or 0 for irrelevant).
my app could simply have a chkbox which is bound to that field (checked (1) for relevance or unchecked (0) for irrelevance) - but i have decided not to. i prefer to have a chkbox which is checked (1) if the field shows irrelevance or unchecked (0) if the field shows relevance; i.e. the chkbox shows the opposite status to the value in the db.
this is the code i have which updates the field when i mousedown on the chkbox to change its state. the purpose of this code is to put the opposite value into the field to which it is unbound (if you catch my meaning):
aside: bear in mind that vb shows true as -1 (rather than +1), so although the value of recordset!fldRelevant will be 0 when the db's value is 0, it will be -1 when the db's value is +1. to get around this, i multiply the recordset's value by -1 to reverse the sign of a 1 (of either type) before subtracting one to turn 1 into 0 or 0 into -1 for the recordset (ado deals with turning this -1 back into 1 for the db):
Code:
Private Sub chkIrrelevant_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
'reverses the chkbox's status for the db
' db recordset vb chk
'True 1 -1 -1 1
'False 0 0 0 0
'to make it irrelevant, turn rs -1 into 0
' rs 0 into -1 - reverse sign and subtract one
Adodc1.Recordset!fldRelevant = Adodc1.Recordset!fldRelevant * (-1) - 1
Adodc1.Recordset.Update
FillOrUnfillChkIrrelevant
End Sub
when i navigate to a record, i want to do the reverse, that is make the chkbox checked (1) when the db's value is 0 and make the chkbox unchecked (0) when the db's value is 1. again, the value of recordset!fldRelevant will be -1 (true) when the db value is +1. this code adds 1 to the recordset's value, turning 0 into a 1 or -1 into a 0 to arrive at the chkbox's value:
(the event i use is mousedown rather than click because another click event would be raised when the value of the chkbox is changed)
Code:
Private Sub FillOrUnfillChkIrrelevant()
'reverses the db's value for the chkbox
' db recordset vb chk
'True 1 -1 -1 1
'False 0 0 0 0
chkIrrelevant.Value = Adodc1.Recordset!fldRelevant + 1
End Sub
to make matters worse, this strange behaviour exhibits itself only at run-time. it behaves as intended when i step through.
does anyone have a clue what is going on?