Results 1 to 8 of 8
  1. #1
    jondavidf is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jun 2012
    Posts
    57

    Setting property of label to visible yes or no, dependent upon other field value

    Hey all,

    I am working on a form to gather medical information for a research project. One of the data items is different types of chronic conditions. If a chronic condition of "diabetes" is entered then we need to gather additional information (annual eye and feet exam dates).

    My form is currently set up where users can select chronic conditions via a drop-down or free type if the condition is not listed to enter the condition onto the record. I also have a listbox immediately below the data entry field which shows chronic conditions previously entered. The listbox populates from a query I've set up.

    What I'd like to do is have a label either be visible or invisible based off whether diabetes is in the listbox or underlying query. Diabetes may be entered a couple different ways, so I'd like the argument to catch any entries containing diabetes, e.g. something like 'If Like & "*" & "diabetes" & "*", then label = visible, else label = invisible'. I just used the If-Then statement to explain and don't know if this is the best approach.

    If I could also disable the Eye Exam Date and Feet Exam Date text boxes if a patient doesn't have diabetes listed, that would be incredible, too!

    Below are a few screenshots of the form so you can get an idea of what I'm talking about.

    Thanks so much for the assistance!

    Jon



    Click image for larger version. 

Name:	ssFrmEncounters.PNG 
Views:	21 
Size:	89.1 KB 
ID:	34337
    (above is pretty much the entire form)
    Click image for larger version. 

Name:	ssChronicConditions.PNG 
Views:	21 
Size:	19.7 KB 
ID:	34338
    (above is the the zoomed in "Chronic Conditions" section and the label I'd like to make visible or invisible in red)

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,972
    Could use a textbox for the 'label'. Have a conditional IIf() expression in the ControlSource.

    Then use Conditional Formatting to enable/disable the date textboxes.

    This way you avoid VBA code.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    apr pillai's Avatar
    apr pillai is offline Competent Performer
    Windows 10 Access 2007
    Join Date
    May 2010
    Location
    Alappuzha, India
    Posts
    209
    If you are familiar with VBA Code then copy and paste the following code into the Form's VBA Module with changes for ListBox Name & Label Name:

    Code:
    Private Sub OnCurrent()Dim ConditionList As ListBox, strItem As String
    Dim listcount As Long, j As Long, condition As String
    Dim cflag As Integer
    On Error GoTo OnCurrent_Err
    
    condition = "Diabetes"
    Set ConditionList = Me.ListBoxName
    listcount = CondditionList.listcount - 1
    strItem = ""
    If listcount = 0 Then
        Exit Sub
    End If
            cflag = 0
            For j = 0 To listcount
           strItem = ConditionList.ItemData(j)
           cflag = InStr(1, strItem, condition)
           If cflag > 0 Then
                  Exit For
           End If
            Next
           If cflag > 0 Then
               Me.LabelRed.Visible = True
           Else
               Me.LabelRed.Visible = False
           End If
    
    OnCurrent_Exit:
    Exit sub
    
    OnCurrent_Err:
    MsgBox Err & ":" & Err.Description
    Resume OnCurrent_Exit
    End Sub
    I have not tested the Code. You may try it out on your own risk. Assumes that you don't have any other code running in OnCurrent() Event Procedure of your Form.
    Last edited by apr pillai; 06-07-2018 at 06:07 AM. Reason: Correction of text

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,992
    A simpler solution with minimal code involves using the Tag property for each object on your form.
    This is fully explained with an example database at https://www.access-programmers.co.uk...d.php?t=293439
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  5. #5
    jondavidf is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jun 2012
    Posts
    57
    I have added the code as Apr suggested as I hadn't seen the latest post by Ridders before I started entering the code. The code does work when the form is loaded initially or if I go into design view and back to form view. How could I get it to update as conditions are being entered, though? I tried adding the following VBA code to the "Save Condition" button:

    Code:
    Forms!frmEncounters.Refresh
    Forms!frmEncounters.Repaint
    Neither the refresh nor the repaint or both together actually refresh the form with the changes.

    Thanks!

    Jon

  6. #6
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,992
    Have a look at this article which explains the differences between refresh, requery, repaint and recalc.
    http://www.projectperfect.com.au/blo...h-and-repaint/
    Easy to get confused

    Personally I'd suggest a different approach to the one you've tried
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,972
    Did you consider non-VBA approach suggested in post 2?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    jondavidf is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jun 2012
    Posts
    57
    Not yet. I will try the non-VBA approach and post an update as soon as I can.
    Last edited by jondavidf; 06-07-2018 at 10:05 PM.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 16
    Last Post: 03-26-2015, 08:35 PM
  2. Dependent Label
    By lugnutmonkey in forum Reports
    Replies: 2
    Last Post: 02-20-2013, 01:16 PM
  3. Setting Custom Field Format Property Problem
    By Weelmaa in forum Programming
    Replies: 2
    Last Post: 02-25-2012, 05:33 AM
  4. Setting visible property of subreport?
    By GaryElwood in forum Reports
    Replies: 1
    Last Post: 09-23-2011, 07:49 PM
  5. Setting a field to be dependent on another
    By CushingMT in forum Forms
    Replies: 0
    Last Post: 11-19-2008, 11:51 AM

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
  •  
Other Forums: Microsoft Office Forums