Results 1 to 4 of 4
  1. #1
    Malikei29 is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Aug 2017
    Posts
    10

    Iif function problems: Beginner's help needed



    I have created a combo box in a form and a table, with the options "yes" or "no"

    If the "yes" Option is chosen, then I want all the Medical Aid Details visible or required

    If the "no" option is chosen, then I don't want the medical Aid Details visible or required.

  2. #2
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 10 Access 2016
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,538
    In the afterupdate event for the combo box

    Change the name of the combobox to what you have named it.
    Code:
    If me.combobox.value = "No" then
    me.textboxA.visible=false   'change the textbox name as needed
    list each of the text boxes to hide
    Else:  list each of the text boxes to unhide by changing to True
    End if

  3. #3
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    That won't address the "not required" aspect, right?. This isn't a job for IIF - it's a job for IF.
    You'll need to use the combo's AfterUpdate event as noted. You'll also need a way to single out the controls involved. For this, I'd enter Reqd (no quotes) in the Tag property for each control involved. I think you can do this in a batch (select all of them then make the Tag entry on the property sheet).
    Are you sure you want to hide the controls rather than disable them?
    You put this into a standard module so that it can be called from many places in your db:
    Code:
    Function HasNoData(vCheckVal As Variant) As Boolean
        HasNoData = False
        If IsNull(vCheckVal) Or vCheckVal = "" Then HasNoData = True
    End Function
    This goes in your combo AfterUpdate event code:
    Code:
    Dim ctl As Control
    Dim svList As String, svList2 As String
    
    svList = "Please enter a value for: " & vbCrLf
    svList2 = ""
    
    If Me.NameOfYourCombo = "Yes" Then
     For Each ctl In Me.Controls
       Select Case ctl.ControlType
       Case acTextBox, acComboBox 'ADD OTHER TYPES AS REQUIRED
          If ctl.Tag = "Reqd" Then
            If HasNoData(ctl) Then svList2 = svList2 & ctl.Controls.Item(0).Caption & vbCrLf
          End If
       End Select
      ctl.Visible = True
    Next
    
    If svList2 <> "" Then
      MsgBox svList & svList2, vbOKOnly, "Missing Information"
      Exit Sub 'comment out or remove this line if you don't want to stop the code when there's missing required info
    Else 'if combo can have other values than Yes or No, then another If is needed. The assumption here is that it's one or the other.
     ctl.Visible = False
    'there's no point in worrying about a control not being required if you can't even see it.
    
    End If
    The label has to be attached/associate with a control otherwise .Item(0).Caption will generate an error. You could use the control name if it's not confusing to the user. Alternatively, you can color its background or do something else to indicate required.
    NOTE - this version of otherwise working code is untested.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    To have this appropriate, when moving from existing Record to existing Record, you'll need to check/format it in the OnCurrent event, as well.

    Linq ;0)>

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

Similar Threads

  1. Replies: 7
    Last Post: 03-23-2015, 07:36 AM
  2. COUNT function help needed
    By Lynn Cohen in forum Access
    Replies: 4
    Last Post: 08-12-2013, 12:52 PM
  3. Replies: 11
    Last Post: 03-21-2012, 12:51 PM
  4. Odd Averaging Function Needed
    By Heatshiver in forum Programming
    Replies: 2
    Last Post: 03-20-2012, 08:26 PM
  5. Help needed in modifying Function
    By Alex Motilal in forum Programming
    Replies: 4
    Last Post: 02-06-2011, 11:59 PM

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