Doing VBA calculations in a form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BUmed
    New Member
    • Aug 2007
    • 26

    Doing VBA calculations in a form

    Normally my forms are simple, but not this one.
    I need to do some calculations in a form and I would normally do them in query but this is more complicated. I have a form that representation of a questionnaire and all the scales are from 1 to 7.

    For example: how well do you sleep at night (choose one) 1 2 3 4 5 6 7.

    Then each of the questions are added up to get a persons total sleep score.
    But with some questions a high score would be need to be converted to a low score.
    For example: Do you wakeup feeling sleepy (choose one) 1 2 3 4 5 6 7.

    So in the first question a 3 would not be changed but if you get a 6 on the second question it needs to be converted to a 2. But in either case a 4 would be the same.
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    "So in the first question a 3 would not be changed but if you get a 6 on the second question it needs to be converted to a 2. But in either case a 4 would be the same."

    Your example is somewhat ambiguous, in regards to what it is, but if you mean the if

    First question = 3

    Second question = 6

    then

    First question needs to be changed to 2

    this will do it:

    Code:
    Private Sub Question2_AfterUpdate()
    
    Select Case Question2
     
     Case 6
       If Me.Question1 = 3 Then Me.Question1 = 2
      
    End Select
    
    End Sub
    I used the Select Case again, which I believe we introduced to you in a previous thread, because I'm guessing that you may have other combinations that you'll have to address.

    Also note that this code is dependent on the first question being answered before the second question is. I assume in this type of questionaire all questions would have to be answered for a sleep score to be computed, so you probably need to set it up so that on creating a record, the focus goes to the first question, and focus can then not go to the second question until a valid entry has been made to the first question.

    Linq ;0)>

    Comment

    Working...