Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2015
    Posts
    10

    Smile Unanswered: Hide ceratin Fields in Form View when a ceratin item is selected from a check box

    Here is the summary I have a Form in access 2010 has information for Diabetes patient and Patient with high blood pressure I have a check box which has two options Diabetes and High Blood pressure I am trying to hide certain feilds when one of the field in my check box is selected for example- once Diabetes is checked I only want the boxes that pertain to Diabetes to show and the others to hide. Please forgive me I am new at this if can please help? Thanks..
    Last edited by cardonas; 03-23-15 at 14:42.

  2. #2
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    495
    Provided Answers: 24
    you could make a sub form that has only the Diabetes fields, then turn on the whole subform when selected...

    subDiab.visible = chkBox = "Diabetes"

  3. #3
    Join Date
    Mar 2015
    Posts
    10

    Thumbs up

    Thank you! so much going to try this I have feeling its going to work ......... Again I am new at this.

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    ***Assuming that you are using a single form NOT continuous forms ***

    there's two elements
    one is how you show or hide certain form (or report) controls
    the other is when do you invoke that action.

    controls in Access speak are objects which have certain methods, or properties. you can for instance hide a cotnrol (using the .visible property), or locked using the .enabled property
    from what you are saying you probably need to use the .visible property and set to true if it shoudl be visible, and false if it shouldn't

    So write a function which received a parameter, and based on that parameter take whatever actions you want.. lets say your controls are called mycontrol1..10, mydiabetescontrol1..10 (for your diabetes specific controls), myBPcontrol01..10 for (wait for it Bloood pressure specific controls)

    the controls which aren't specifc will not be touched (mycontrol01..mycontrol10)
    Code:
    public sub SetControlVisibilityByHealthType(HealthType as String)
      if UCASE(HealthType) = "DIABETES" then
        mydiabetescontrol01.visible = true
        mydiabetescontrol02.visible = true
        '...
        mydiabetescontrol10.visible = true
        'now for the blood pressure specific controls
        mybpcontrol01.visible = false
        mybpcontrol02.visible = false
        '...
        mybpcontrol10.visible = false
      elseif UCASE(HealthType) = "BLOOD PRESSURE" then
        'then repeat the code block above but reverse the true / false bit
      endif
    end sub
    why use an if / elseif construct?
    you have 3 states that a row coudl be (iuts a diabetes row, its a blood pressure row or its neither / not determined yet

    well you could use a select case (and arguably is better for more than one choice)
    as a general rule when coding ANYTHING cover the expected bases. dont' assume exprerssly code for specific states. yes its more work, but I'd argue makes your code more maintainable (and maintainable not just for you. say the comedians, sorry users, decide a third condition should be handled by the same system (say stroke) then becuase you have explciit diabetes cawe, blood pressure case its realtively easy for a new developer to add nbew conditions.

    ..actually you'd be better off defining an enumeration so instead of passing the parameter as text you'd pass it as an enumeration (think if an enumneration as a limited list of possible values. although its arguable here that an enumeration is required its good practice especailly if you write code which could be used by others. the real advanatage of the enumeration as opposed to passing as a string =value is that you cannot get an invaliud value (say a user passed 'blood press' instead of 'blood pressure'.. it protects you aaginst typos and not in list errors it can also help make code easier to understand

    so that sets the visibility based on the the specified parameter. now you need to decide when the controls visibility shoudl be triggered. well that would be when
    the value of the control that 'decide' this is a diabetes or blood pressure control changes
    OR
    when the current displayed row changes
    or....?

    so haviing written your function you need to call that function form various events that fire in background when you use a form.
    ...when a single from's data row changes the oncurrent event fires. so that woudl be how you'd show or hide historic data by calling the function from there
    the thorny question is when the data in the current row changes (that may happen on an edit of an exisiting row or adding a new row.
    so set the visibility based on the onchange event or the relevant control.

    as to what the relavant control is, who knows, thats down to your design., it could be a combo, a list box, a text box, whatever. (you'd be better off using a combo or list box, and even better off using a combo box that has the values of the enumerated list as hidden columns


    but the 'right' way to do this I'd argue is to have two subforms that hang off a single 'visit' form form. the user selects what ype of condition it is, and then dispalys the relavnt subf form

    ....or used a tabbed dialog to the user can see any diabetes obs, or any bp, or any....
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Mar 2015
    Posts
    10
    Thank you but since I am new at this I am not getting it as I should I expect (forgive me) this is what I put below ... I spoke with client about subforums and she seem to be on the okay side with it so I am going to see if I can just do a subforum ... Thank you again.


    Private Sub SetControlVisibilityByReasonforvisit()
    If UCase(Reasonforvisit) = "MEDREC" Then
    InitialA1C.Visible = True
    6MonthA1C.Visible = True
    OTCnotneeded.Visible = False
    Rxnotneeded.Visible = False
    ElseIf UCase(Reasonforvisit) = "DM" Then
    InitialA1C.Visible = False
    6MonthA1C.Visible = False
    OTCnotneeded.Visible = True
    Rxnotneeded.Visible = True
    End If
    End Sub


    Medrec= High Blood pressure
    DM= Diabetes

  6. #6
    Join Date
    Mar 2015
    Posts
    10

    Unhappy

    Sorry- having trouble on where I should put the code for the subform when I go into to do the change it gives me a ( click) so not sure if I was in the right place or if I need to do it under the afterupdate event?

Tags for this Thread

Posting Permissions

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