Results 1 to 5 of 5
  1. #1
    Lyla is offline Novice
    Windows XP Access 2016
    Join Date
    Aug 2018
    Posts
    6

    VBA multiple values

    Hi! I am trying to lock a certain field in a form when a specific option is given in another field.
    For normal variables this works with the following code:

    Private Sub PREG_AfterUpdate()


    Select Case Me.PREG
    Case "1"
    Me.GEST.Enabled = True
    Case Else
    Me.GEST.Enabled = False
    Me.GEST.Value= Null
    End Select
    End Sub

    However, when one of the variables stores multiple values this code doesn't work.

    Anyone knows how to fix this?

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    variables cannot store multiple values, only a single one.

    So perhaps explain in more detail what you mean - provide some examples

  3. #3
    Lyla is offline Novice
    Windows XP Access 2016
    Join Date
    Aug 2018
    Posts
    6
    Thanks! So when you have table and create a "field name" (for example pregnancy = PREG) and the data type is a lookup from another table (numberic) (1 ,2,3). You have the option to "Allow multiple values".
    When you try to block a field (so gestation week = GEST) in a form based on the answer given with PREG ( number 2 or 3), then the code I us does not work:

    Private Sub PREG_AfterUpdate()
    Select Case Me.PREG
    Case "1"
    Me.GEST.Enabled = True
    Case Else
    Me.GEST.Enabled = False
    Me.GEST.Value= Null
    End Select
    End Sub

  4. #4
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    These are known as multivalued fields.
    Most developers avoid them like the plague, as they aren't correctly normalized data, but a bit of a kludge to avoid a proper data structure.

    More here https://stackoverflow.com/questions/...ds-a-good-idea
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    As Minty says, multivalue fields have their uses but limit what else can be done. Although they display the selected items in a single control, they are not stored that way. They are stored as a list of single values - effectively another table but hidden and not very accessible.

    To achieve what you want you would need to iterate through this table/list to see if 1 has been selected and then apply the rest of the code. I'm not sure how you would do that because I don't use them. Here is a link to some code that you might be able to use to see if 1 has been selected http://allenbrowne.com/ser-42.html

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

Similar Threads

  1. Query for multiple values
    By Paul D in forum Queries
    Replies: 1
    Last Post: 01-15-2018, 09:54 AM
  2. Replies: 5
    Last Post: 11-19-2017, 12:28 PM
  3. Filter with multiple values
    By paloma.rz in forum Programming
    Replies: 3
    Last Post: 08-24-2017, 08:43 AM
  4. Replies: 3
    Last Post: 10-30-2016, 05:50 AM
  5. Replacing many values at once in a multiple values checkbox field.
    By ConfusedDatabaseDesigner in forum Forms
    Replies: 2
    Last Post: 07-20-2012, 08:58 AM

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