Tick Boxes

sagsh

Registered User.
Local time
Today, 10:41
Joined
Jul 18, 2004
Messages
19
I have a form with tick boxes on it which when pressed runs an afterupdate macro that inputs data into my table. Which works fine except when a user changes their mind and unselects the tickbox - access goes and puts the same field into the database...

the code is as follows:-

Private Sub Check2_AfterUpdate()
Me.Features = Nz(Me.Features) & ",value to be added to database"
End Sub

Ideally what I need it to do is remove the value added to the database but the problem is that I have five tick boxes on my form and all five could be ticked and then the first unselected. As you can see the afterupdate script adds to the value in the database field I therefore need somehow to strip just that portion of the text.

Have I over complicated this or could I do this another way?

Thanks for any help.
Sags
 
You need to check the value of the tick-box just updated before you run your actions.

Something like

Dim boolChk As Boolean
boolChk = Me.Check2

Select Case boolChk
Case Is = True
' Place the code here that you want if checkbox is ticked
Case Is = False
' Place the code here that you want if checkbox is unticked
End Select
 
Hi,

I suggest to use one sub to build the value to be saved, which you call from each Check_AfterUpdate()"
Code:
Private Sub CheckX_AfterUpdate()
  ChangeDatabaseValue()
End Sub

Private Sub ChangeDatabaseValue()
  If Me!Check1 then Me!Features = "value1"
  If Me!Chekc2 then Me!Features = Me!Features & "value2"
  ...
end sub
 
I tried the ChangeDatabaseValue() script and I got an error:-
compile error syntax error - I have checked the script and it is exactly as you said so what could possibly be wrong?

please help

Regards
Sags
 
Something like


Code:
Dim myString As String
Dim boolChk As Boolean

boolChk = Me.Check2
myString = "Value to be added"

Select Case boolChk
Case Is = True
Me.Features = Me.Features & myString
Case Is = False
Me.Features = Left(Me.Features,Len(Me.Features)-Len(myString))
End Select

This should work if the 'value to be added' ie myString remains unchanged between the time they tick and untick the checkbox.
 
Thanks Dan_Cat this works fine until someone ticks several boxes and thn hesitates and goes back to one already selected and unticks it.
Do you know a way around this?

Thanks for any help
Sags
 

Users who are viewing this thread

Back
Top Bottom