Check-boxes issues

ahuvas

Registered User.
Local time
Today, 02:25
Joined
Sep 11, 2005
Messages
140
Its a long story but i have designed a form where there are four check boxes per question - there are two columns (Left and Right) with two boxes in each - L1, L2, R1, R2. There are a 8 questions (each with 4 boxes) but it I get the first one down I should be fine

These represent the preferences for handedness.

These rules for ticking them are as follows:

1. If the user doesnt do the task he will keep all four boxes unticked
2. If the user doesnt have a preferences he needs to put a tick, one in each colum
3. If he has a strong preference for a particular task he needs to put two ticks in the column for the hand they he prefers

I have created code so that:

a. I can try and ensure that the participant follows these rules
b. The check-boxes can return a text response.


Here is what I have come up with so far:

Private Sub Q1L1_AfterUpdate()

If Me.Q1L1 = -1 And Me.Q1L2 = -1 Then

Me.Q1R1.Locked = True
Me.Q1R2.Locked = True
Me.Q1R1.Controls(0).ForeColor = RGB(221, 221, 221)
Me.Q1R2.Controls(0).ForeColor = RGB(221, 221, 221)
Me.Q1R1.Value = 0
Me.Q1R2.Value = 0
Me.Q1Answer.Value = "Strong Left"

Else

Me.Q1R1.Locked = False
Me.Q1R2.Locked = False
Me.Q1R1.Controls(0).ForeColor = RGB(0, 0, 0)
Me.Q1R2.Controls(0).ForeColor = RGB(0, 0, 0)
Me.Q1R1.Value = Null
Me.Q1R2.Value = Null
Me.Q1Answer.Value = Null

End If

If Me.Q1L1 = -1 And Me.Q1R1 = -1 Then
Me.Q1Answer.Value = "Neither Right nor Left"

Else

Me.Q1Answer.Value = Null

End If

If Me.Q1L1 = -1 And Me.Q1R2 = -1 Then
Me.Q1Answer.Value = "Neither Right nor Left"

Else

Me.Q1Answer.Value = Null

End If

End Sub

===============

The code successfully causes the right column for example to grey out if two ticks are in the left column and returns the value "Strong Left" for example to the text box.

I have a few issues:

1. I do not think the ifs and endifs are necessarily in the right place.
2. Now if I check on either R1 or R2 and then try to click on L1 so that I can return the text "Neither Right nor Left" it causes the R1/R2 box to uncheck.
but it doesnt happen the other way if I click L1 first and then R1/2 (I have put a code for this combination in yet).

THis code will have to be repeated for all the chekcboxes since even though logically the users will click from left to right, I cant be sure that they will.


Does anyone have any ideas?

UPDATE: I took out the endifs between conditions and replaced the ifs of the 2nd, 3rd and 4th conditions etc with elseif, and ended on a else statement. Its getting there but its not working properly. Its clearly the positions of the if, thens and elseifs thats the problem.
 
Last edited:
You do 3 different test, all of which can be true?
Each one gives a different result in
Me.Q1Answer.Value =

Is this what you want? maybe you need some Exit Sub in there.

Brian
 
I have to do the three tests (each of which will return a different answer to Q1Answer field) however only one of the conditions can be true.

The three tests ask:

If the last box (in this case I can just ticked - L1) and L1 are both positive (-1) then I return the value Strong Left

If the last box (in this case I can just ticked - L1) is positive and R1 is positive then return value "Neither Left nor right"


If the last box (in this case I can just ticked - L1) is positive and R2 is positive then return value "Neither Left nor right"

It cannot be that I tick L1, L2 and R(1 or2) since by ticking L1 and T2, R1 and R2 become disabled and the value of 0 is inserted into the table.
 
Can you give a value to a locked control? This is a proper question as I don't know the answer but my instinct is to set the value then lock.

Brian
 
Here I have uploaded a file that recreates the form.

I have only included the first bit that works

As you can see there are two boxes each in each column

I want the person to tick either oine boc in each column, two boces in one column, or no boxes.


The code I have written will be attached to each box (making the appropriate changes) since I am uncertain which order the boxes will be chosen or if they are going to put one tick in each column will they tick the box in the first sub-column or will they chose to tick the box in the right sub-column

HOpe this helps.
 

Attachments

I think that you are tackling this incorrectly, if you place the code after each checkbox update then you are going to try to get an answer before the user is ready, I would put the code in the dble click event of Q1answer.

brian
 
The text box will be invisible to the user? Its for me later when I run a query for a report.

The code has to be attached to the After update event because for example after the user clicks on the L1 box access has to decide whether to make R1 and R2 locked or not.

I could put the command re: text box on the Form close event but I dont see any added benefit.


In general, how do you structure the if-then-else-else if statement if you have multiple but mutually exclusive events - If one of the events occur the others cannot be true. Furthermore if the first event is not occuring, then access has to continue with the statements essentially.
 
The text box will be invisible to the user? Its for me later when I run a query for a report.

In that case I would not put the answer on the form, just use the locking, which you say works, and sort out the answer in the query.

Brian
 
Okay I will do that and see what I can come up with :)

Thanks.
 
As I see it in the query you will have a possible 5 answers, theoterically, from none to all 4 ticked.
so a function, say fgetanswer could be written with the code

Dim intTotal as integer

intTotal = L1+l2+abs(r1)+abs(r2) ' this gives an answer from -2 to +2

then use a select case to convert this to a string for fgetanswer

Brian
 
Last edited:
All 4 can never be ticked - at most you can only have two ticked - the two on the left side, the two on the right side or one on each side.
 
I did say theoretically, and whether they are or not does not impact on the concept, you can always decide to ignore any option in the Select Case. but of course all 4 = 1left+1right = none selected ie Total = 0.
You do understand my approach?

Brian
 
Last edited:
Im sorry that I havent had a lot of time to think about this last week but I will try and solve the problem this week.
 

Users who are viewing this thread

Back
Top Bottom