Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Join Date
    Apr 2007
    Posts
    81

    Unanswered: 4 Option Buttons

    Hi

    I have a continues form “Form1” contained 4 checkmarks, 4 options and TextboxResult.

    I need code for:
    each Checkmark = 0 if I select = 1
    Option1 = Checkmark1
    Option2 = Checkmark2
    Option3 = Checkmark3
    Option4 = Checkmark4
    Textbox Result =Option1+ Option2+ Option3+ Option3

    I need code or any way to get as above information, that form for school tests. and result come to the “TextboxResult”

    or check the attach
    I need some modifications in this file.

    When I choose checkA, optionA selected automatically, I do not want to work with each other,

    I need choose CheckA and OptionB result would be zero or choose CheckA and OptionA result would be one.

    thanks
    Attached Files Attached Files

  2. #2
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Thanks for supplying the mdb (it helps.) I'd first rename your checkboxes as it's a pain writing the code twice (and having a field called: check31 will make your life wickedly long for troubleshooting in the future.)

    I think your problem lays in that the code is in the controlsource of OptionA, OptionB, etc... Remove this and instead put code in your OnClick event of CheckA (CheckB, etc.). In that code, you will then need to add in a test to see if CheckA is true or false and depending on the value, either populate OptionB (or whatever Option you want to) with it's values (one or zero) (ie. me!OptionB = 0). If it's a continuous form, you'll have problems as each record will be set to the same value. You can't do individual record values for an unbound field (or field bound to a formula) for continuous records. Your best option in this case is to make the OptionA, OptionB, etc (and Check31, Check32, etc.). fields bound to a table (which also allows you to utilize the very nice Conditional Formatting option.)

    Remember that code in the ControlSource of a field is set to usually directly tie to the value within another field (and automatically changes when the other value is changed.) This is it really only updatable via the other field (and not through code.) If you leave this blank or tie it to a field in a table, you can then have more control of what values you want to put into that field from record to record via a bit of vba code.

    I'm assuming you're also going to create and add in the tie to the backend table after you've finished working out the code issues. As of now, this is really not doing anything productive (unless you have another form based off of it or other code it's related to.)
    Last edited by pkstormy; 12-22-08 at 21:45.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  3. #3
    Join Date
    Apr 2007
    Posts
    81
    thank you so much for reply.

    same Question in other way.

    Should be come the correct answer score to the result box.
    if choose A should be the result = 0.
    if choose B should be the result = 1.
    if choose C should be the result = 0.
    if choose D should be the result = 0.

    How I specify the correct answer.

    Maybe you get my idea clearly in this attachment.

    I need some modifications in one of files.

    thanks
    Attached Files Attached Files

  4. #4
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    I looked at your attachment and I'm not sure I understand. I will try to look at it again later but the "if choose A should be the result = 0, etc...." is confusing to me. Maybe someone else can understand this better. Again, I'll try to look at it later but it makes it difficult when you don't name your fields to something that makes more sense.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  5. #5
    Join Date
    Feb 2006
    Posts
    11

    try this

    You can't really get what you need without using the event property for each control and add required code as attached.

  6. #6
    Join Date
    Feb 2006
    Posts
    11

    Attachment

    Sorry forgot the attachment

  7. #7
    Join Date
    Apr 2007
    Posts
    81
    Hi

    thank you so much for reply.

    Should be come the correct answer score to the result box.

    I want like this below by any way code or without code.
    4 X $ =

    A- 15 B- 16
    C- 18 D- 20

    if choose A should be the result = 0.
    if choose B should be the result = 1.
    if choose C should be the result = 0.
    if choose D should be the result = 0.


    thanks

  8. #8
    Join Date
    Apr 2007
    Posts
    81
    4 X 4 =

    A- 15
    B- 16
    C- 18
    D- 20

    if choose A should be the result = 0.
    if choose B should be the result = 1.
    if choose C should be the result = 0.
    if choose D should be the result = 0.


    thanks

  9. #9
    Join Date
    Feb 2006
    Posts
    11
    Add field [answer] to table 1, populated with the answer to the question.
    add the code to the click event for the check boxes.

    you could create a function and call the function from the click event which would be the correct but more complex way of doing it.

    Private Sub Check31_Click()

    If [Check31] = True Then
    [Check33] = False
    [Check35] = False
    [Check37] = False
    End If

    If [Check31] = True And [FldAns1] = DLookup("[ANSWER]", "[TABLE1]") Then [Text39] = 1 Else [Text39] = 0
    If [Check33] = True And [FldAns2] = DLookup("[ANSWER]", "[TABLE1]") Then [Text41] = 1 Else [Text41] = 0
    If [Check35] = True And [FldAns3] = DLookup("[ANSWER]", "[TABLE1]") Then [Text43] = 1 Else [Text43] = 0
    If [Check37] = True And [FldAns4] = DLookup("[ANSWER]", "[TABLE1]") Then [Text45] = 1 Else: [Text45] = 0

    End Sub

    Private Sub Check33_click()
    If [Check33] = True Then
    [Check31] = False
    [Check35] = False
    [Check37] = False
    End If
    If [Check31] = True And [FldAns1] = DLookup("[ANSWER]", "[TABLE1]") Then [Text39] = 1 Else [Text39] = 0
    If [Check33] = True And [FldAns2] = DLookup("[ANSWER]", "[TABLE1]") Then [Text41] = 1 Else [Text41] = 0
    If [Check35] = True And [FldAns3] = DLookup("[ANSWER]", "[TABLE1]") Then [Text43] = 1 Else [Text43] = 0
    If [Check37] = True And [FldAns4] = DLookup("[ANSWER]", "[TABLE1]") Then [Text45] = 1 Else: [Text45] = 0

    End Sub

    Private Sub Check35_click()
    If [Check35] = True Then
    [Check31] = False
    [Check33] = False
    [Check37] = False
    End If
    If [Check31] = True And [FldAns1] = DLookup("[ANSWER]", "[TABLE1]") Then [Text39] = 1 Else [Text39] = 0
    If [Check33] = True And [FldAns2] = DLookup("[ANSWER]", "[TABLE1]") Then [Text41] = 1 Else [Text41] = 0
    If [Check35] = True And [FldAns3] = DLookup("[ANSWER]", "[TABLE1]") Then [Text43] = 1 Else [Text43] = 0
    If [Check37] = True And [FldAns4] = DLookup("[ANSWER]", "[TABLE1]") Then [Text45] = 1 Else: [Text45] = 0

    End Sub

    Private Sub CHECK37_click()
    If [Check37] = True Then
    [Check31] = False
    [Check33] = False
    [Check35] = False
    End If
    If [Check31] = True And [FldAns1] = DLookup("[ANSWER]", "[TABLE1]") Then [Text39] = 1 Else [Text39] = 0
    If [Check33] = True And [FldAns2] = DLookup("[ANSWER]", "[TABLE1]") Then [Text41] = 1 Else [Text41] = 0
    If [Check37] = True And [FldAns4] = DLookup("[ANSWER]", "[TABLE1]") Then [Text45] = 1 Else: [Text45] = 0
    If [Check35] = True And [FldAns3] = DLookup("[ANSWER]", "[TABLE1]") Then [Text43] = 1 Else [Text43] = 0



    End Sub

  10. #10
    Join Date
    Apr 2007
    Posts
    81
    Hi

    I do as you write but come error msg. please check the attach to see the update.

    thank you,
    Attached Files Attached Files

  11. #11
    Join Date
    Feb 2006
    Posts
    11

    check box

    see my post named check box

  12. #12
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    ▲ The only post you have named "check box" is one which says to check the post named "check box". Circular reference error!!

    I think you mean your TOPIC named "check box example".
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  13. #13
    Join Date
    Apr 2007
    Posts
    81
    Hi acorn
    Thank you so much, that example in your post "check box example" is very good.

    else I need Continuous Form if you can modifications in Form11.

    thanks

  14. #14
    Join Date
    Feb 2006
    Posts
    11

    Continuous form

    I don't mind helping but i don't think i should do it for you. you wouldn't learn much.

    You might want to put an autonumber key on table 1 and set the form to requery to the next record in single form view once the a box has been checked.

    something like
    VB code:
    Cmpl = Msgbox " are you happy with your choice", "Input", VbYesNo

    Cmpl= vbyes the docmd.gotorecord next

    something like
    if you want to use a continous form then you will have to use expresions in the score text box

    something like

    iif(check31=true,iif([fldans1]=dlookup("[answer]","[table1]","[id]=forms![form1]![id]),1,0),0)

    but you will need to ad an id field to table1 and an id textbox to your form.

    Good luck

  15. #15
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Quote Originally Posted by acorn
    I don't mind helping but i don't think i should do it for you. you wouldn't learn much.
    good point
    there is an age old comment.. learn by doing.
    there are lots of helpful people here and elsewhere. However there are some people who turn to this resource at the first sign of a problem, becusae they can't or won't think the problem through. if you make an attempt to solve the problem.. there is a chance you will get a soluton quicker than posting here, you learn more and you develop.. you are able to take on more complex problems.

    there is also another aspect that you understand what is going on so if you hgave to revisit the code you can interpret what happens there. probably the most confusing result of going elsewhere is that there is rarely one true answer, and there is always a risk that you will get similar but different answers. so take ownership of any code you get and understand what is being proposed.

    HTH
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •