check for data if another combobox has data

Posted on 2011-10-20
Last Modified: 2012-05-12
I have the following comboboxes below:
ComboA1         ComboB1
ComboA2         ComboB2
ComboA3         ComboB3
.......                  ..............

I want to write some VB6 code that will check all the comboboxes from A1 to A5.  If any of them have any text in them, then the code will have to check the equivalent combobox in the right column (B1 to B5) to make sure that has text also.  If it doesn't then the user will need to enter data.  How can I accomplish this?
Question by:al4629740
    1 Comment
    LVL 14

    Accepted Solution

    If Len(ComboA1.Text) Then
       If Len(ComboB1.Text) = 0 Then
          Rem *** Insert data-entering routine here ***
       End If
    End If

    Repeat the above for Combo 2 to 5.

    But ya know, a slicker way to do it is to make an array of comboboxes. For instance:

    ComboA1 becomes cboData(0)
    ComboA2 becomes cboData(1)
    ComboA3 becomes cboData(2)
    ComboA4 becomes cboData(3)
    ComboA5 becomes cboData(4)
    ComboB1 becomes cboData(5)
    ComboB2 becomes cboData(6)
    ComboB3 becomes cboData(7)
    ComboB4 becomes cboData(8)
    ComboB5 becomes cboData(9)

    Then you can use:

    For i = 0 to 4
       If (Len(cboData(i).Text ) > 0) And (Len(cboData(i + 5).Text ) = 0) Then
          Rem *** Insert data-entering routine here ***
       End If
    Next i

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
    Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now