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

    Unanswered: How to enable and disable a subform based on a combo/check box selection

    I have a combo/checkbox has two categorys to choose from one is "DM and other is "Med" ... I made a subform that only pertains to category "DM" I would like to enable/disable the subform depending on what category is selected in the combo/checkbox ... I think I have the code down but I am not sure where to put it for example do I put it in properties under Afterupdate or click or change?? Sorry I am new at this..any help please!!!!

  2. #2
    Join Date
    Mar 2015
    Posts
    27
    Quote Originally Posted by cardonas View Post
    I have a combo/checkbox has two categorys to choose from one is "DM and other is "Med" ... I made a subform that only pertains to category "DM" I would like to enable/disable the subform depending on what category is selected in the combo/checkbox ... I think I have the code down but I am not sure where to put it for example do I put it in properties under Afterupdate or click or change?? Sorry I am new at this..any help please!!!!
    Put your code in the After_Update event. Your comment is unclear as to whether you want to use a combo box, or a check box but both have an After_Update event and that is where you should put your code.

  3. #3
    Join Date
    Mar 2015
    Posts
    10
    Sorry about that I have a checkbox and I was just confuse on where to put the code going to give it a try and see what happens thank you.

  4. #4
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Quote Originally Posted by cardonas View Post

    ... I think I have the code down but I am not sure where to put it for example do I put it in properties under Afterupdate or click or change...
    Not sure about the 'do I put it in properties under Afterupdate;' Using code, it needs to be in the Form's code module, which can be accessed through the Properties Pane, but not actually placed in the AfterUpdate Property's box in the Properties Pane, if you get the difference.

    Also, so that the Subform will be enabled/disabled appropriately, for a given Record, the same code needs to be placed in the Form_Current event.

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    Join Date
    Mar 2015
    Posts
    10

    Question

    Thanks I found out that the hard way .... But I am still hjaving trouble here is my code example


    subDiab.visible = chkBox = "DM"

    not sure if I need to do anything else?? or what I missing

  6. #6
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Is this a Combobox or a Checkbox; it has to be one or the other! Assuming it is a Combobox

    Code:
    If Me.ActualComboboxName  = "DM" Then
    
      SubDiab.Visible = True
    
    Else
    
     SubDiab.Visible = False
    
    End If

    replacing ActualComboboxName with the actual combobox name. And, as noted before, it needs to be in the AfterUpdate event of the Combobox and in the Form_Current event.

    Also note that I used the Visible Property, as your example showed, although your OP referred to Enabling/Disabling the Subform.
    If you're using a Checkbox, you'll have to give us a better explanation of its setup.

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  7. #7
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Code:
    subDiab.visible = chkBox = "DM"
    ?
    I'm not surprised that doesnt' work, let me guess it doesn't compile either....

    effectivley waht you are saying is
    set the visible property of the control sub Diab to the value of chkbox which should be equal to 'DB'. there are seomthigs you can do in VBA which on the face of it look odd but as a general rule you sholuld only set properties using the expected datatrype which is a boolean (yes/no or true/false).

    a checkbox is designed to be used as an option for a specidfic item, as opposed to a radio button which means either this, or that (or another) option.
    I suspect you probably want to use a radio button in place of a check box, but no matter


    lets assume your checkbox is called ckbDiabetes and it has two states (set / unset). if its checked then display the diabetes form, if it isn't do something else
    Code:
    if ckbDiabetes = vbTrue then 'it may be ckbDiabetes.checked or even ckbDiabetes.value
      subDiab.visible = vbtrue
      subBloodPrferssure.visible = vbfalse
    else
      subDiab.visible = vbfalse
      subBloodPrferssure.visible = vbtrue
    endif
    this is actually one of the occasions when you can short circuit the if statement alltogether as the checked property is boolean, so you coudl assign the value of the checkbox control diorectly to the form visibility

    Code:
      subDiab.visible = ckbDiabetes
      subBloodPrferssure.visible = NOT ckbDiabetes 'invert / flip the value of the checkbox
    I'd rather be riding on the Tiger 800 or the Norton

  8. #8
    Join Date
    Mar 2015
    Posts
    10

    Thumbs up

    Thank you . I realzie what I did wrong from your post . Thanks again!

  9. #9
    Join Date
    Mar 2015
    Posts
    10
    So this is what I got so far but I think I have one field off
    I have a combo box........ combo box name is ( REASON FOR VISIT) I put the code in the After update ...(not the cloumn) but in the correct place and I put it in the Current in forum but I am getting this kick back with the combo name in the current Form


    Private Sub form_Current()
    If Me.Reason_for_Visit = "DM" Then

    Her.Visible = True

    Else

    Her.Visible = False

    End If


    End Sub

  10. #10
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    What happens if you try and debug your code. When the code halts in the immediate window type ?reason_for_visit.text

    Access uses an object notation such as objectname.propertyname
    there is a default property returned if you just use the objectname, however id argue its always good practice to explicitly refer to the property you want to.

    But wgat is the error reported
    I'd rather be riding on the Tiger 800 or the Norton

  11. #11
    Join Date
    Mar 2015
    Posts
    10

    Question

    I am getting an error that says RUN-Time error"13" Type Mismatch


    and here is my code exact and when I debug it it highlights the combox name



    Private Sub form_Current()
    If Me.Reason_for_Visit = "DM" Then

    Her.Visible = True

    Else

    Her.Visible = False

    End If


    End Sub




    Private Sub Reason_for_Visit_AfterUpdate()
    If Me.Reason_for_Visit = "DM" Then

    Her.Visible = True

    Else

    Her.Visible = False

    End If


    End Sub

  12. #12
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    And what happens if you display the default property (just prefix the object name with a ?) In the immediate window

    What property do you think you should be using. Combo boxes are a composite control. Composed of a text box and a list box
    I'd rather be riding on the Tiger 800 or the Norton

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
  •