Results 1 to 5 of 5
  1. #1
    Derek_123 is offline Novice
    Windows XP Access 2013 64bit
    Join Date
    Jun 2023
    Posts
    2

    Validation to check only one dropdown box has a value

    Hi All,



    I have 3 drop down boxes on my form for 3 different types . I want to put a validation on the save event that will make sure only one box has a value in it . If the users have typed in value in all 3 boxes or 2 boxes then show an error saying "Only one type must be selected".

    Any help will be much appreciated . Thanks.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    this function can be used for various forms

    usage:
    If IsValidForm() then
    SaveData
    else
    'prevent user from stuff
    endif



    Code:
    Private Function IsValidForm() As Boolean
    Dim vMsg
    dim iTot as integer
    
    
    if not IsNull(cboBox1) then iTot = iTot + 1
    if not IsNull(cboBox2) then iTot = iTot + 1
    if not IsNull(cboBox3) then iTot = iTot + 1
    
    
    Select Case True
       Case iTot >1
          vMsg = "Only fill 1 box"
      case iTot = 0
          vMsg = "Must fill 1 box"
     End Select
    If vMsg <> "" Then MsgBox vMsg, vbCritical, "Required Field"
    IsValidForm = vMsg = ""
    End Function

  3. #3
    Derek_123 is offline Novice
    Windows XP Access 2013 64bit
    Join Date
    Jun 2023
    Posts
    2
    Thanks a lot for your help. It worked fine

  4. #4
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Why three combos and not just one with the combined row sources of the original three?

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I have 3 drop down boxes on my form for 3 different types
    Is that because you have 3 fields to define the 'type' of one thing? If yes, it's very likely that your tables are not properly designed. You should research db normalization if that is the case.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Validation rule to check for a space
    By sra2786 in forum Access
    Replies: 1
    Last Post: 11-24-2018, 02:24 PM
  2. Validation check
    By lamore48 in forum Programming
    Replies: 4
    Last Post: 10-23-2018, 04:53 PM
  3. Replies: 41
    Last Post: 12-06-2016, 08:40 AM
  4. Data Validation: check for special characters
    By mabrande in forum Access
    Replies: 11
    Last Post: 08-22-2013, 02:18 AM
  5. Debug on validation check
    By GraemeG in forum Programming
    Replies: 1
    Last Post: 02-23-2011, 01:19 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