Solved

Determine which value is selected in an Excel form option group

Posted on 2011-02-25
2
230 Views
Last Modified: 2012-05-11
I have a form that dynamically presents the user with the required fields to be filled in on an Excel form.  When the user saves the data, I first need to validate that the required fields are populated.  First the user selects on of the options from an option group, this determines what fields are visiable.  So, how do I deterine which option was selected in the group so I can check the data controls?  I don't think what I have is the right direction (and it does not work!)
Private Sub btnSave_Click()
Dim intValue As Integer
intValue = Me.fraPortfolioGroup
Select Case intValue
    Case Me.optActivePortfolios
        If IsNull(Me.txtPortfolioCode) Or IsNull(Me.txtPortfolioName) Or _
            IsNull(Me.txtURLSectorSummary) Or IsNull(Me.txtURLSectorDetail) Or _
            IsNull(Me.txtURLRatingSummary) Or IsNull(Me.txtURLRatingDetail) Then
            Call NullAddProfileMessage
                Exit Sub
    Case Me.optActiveMiscel
        If IsNull(Me.txtPortfolioCode) Or IsNull(Me.txtPortfolioName) Or _
            IsNull(Me.txtURLSectorSummary) Or IsNull(Me.txtURLSectorDetail) Then
            Call NullAddProfileMessage
                Exit Sub
    Case Me.optActivePortMastStats
        If IsNull(Me.txtPortfolioCode) Or IsNull(Me.txtPortfolioName) Or _
            IsNull(Me.txtURLSectorSummary) Then
            Call NullAddProfileMessage
                Exit Sub
    Case Me.optIndexPortfolios
        If IsNull(Me.txtPortfolioCode) Or IsNull(Me.txtPortfolioName) Or _
            IsNull(Me.txtURLSectorSummary) Or IsNull(Me.txtURLSectorDetail) Or _
            IsNull(Me.txtURLRatingSummary) Or IsNull(Me.txtURLRatingDetail) Then
            Call NullAddProfileMessage
                Exit Sub
    Case Me.optIndexMiscel
        If IsNull(Me.txtPortfolioCode) Or IsNull(Me.txtPortfolioName) Or _
            IsNull(Me.txtURLSectorSummary) Or IsNull(Me.txtURLSectorDetail) Then
            Call NullAddProfileMessage
                Exit Sub
    Case Me.optIndexSFPortfolios
        If IsNull(Me.txtPortfolioCode) Or IsNull(Me.txtPortfolioName) Or _
            IsNull(Me.txtURLSectorSummary) Or IsNull(Me.txtURLSectorDetail) Then
            Call NullAddProfileMessage
                Exit Sub
    Case Me.optIndexPortMasterStats
        If IsNull(Me.txtPortfolioCode) Or IsNull(Me.txtPortfolioName) Or _
            IsNull(Me.txtURLSectorSummary) Then
            Call NullAddProfileMessage
                Exit Sub
End Select

End Sub

Open in new window

0
Comment
Question by:ssmith94015
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 18

Accepted Solution

by:
Cory Vandenberg earned 500 total points
ID: 34981080
You could use a UDF like the one written by Chip Pearson here

Selected Option Button

or you could switch your Select Case statement to an If-ElseIf-Else logic like below

WC
Private Sub btnSave_Click()
Dim intValue As Integer
intValue = Me.fraPortfolioGroup
If Me.optActivePortfolios Then
        If IsNull(Me.txtPortfolioCode) Or IsNull(Me.txtPortfolioName) Or _
            IsNull(Me.txtURLSectorSummary) Or IsNull(Me.txtURLSectorDetail) Or _
            IsNull(Me.txtURLRatingSummary) Or IsNull(Me.txtURLRatingDetail) Then
            Call NullAddProfileMessage
                Exit Sub
ElseIf Me.optActiveMiscel Then
        If IsNull(Me.txtPortfolioCode) Or IsNull(Me.txtPortfolioName) Or _
            IsNull(Me.txtURLSectorSummary) Or IsNull(Me.txtURLSectorDetail) Then
            Call NullAddProfileMessage
                Exit Sub
ElseIf Me.optActivePortMastStats Then
        If IsNull(Me.txtPortfolioCode) Or IsNull(Me.txtPortfolioName) Or _
            IsNull(Me.txtURLSectorSummary) Then
            Call NullAddProfileMessage
                Exit Sub
ElseIf Me.optIndexPortfolios Then
        If IsNull(Me.txtPortfolioCode) Or IsNull(Me.txtPortfolioName) Or _
            IsNull(Me.txtURLSectorSummary) Or IsNull(Me.txtURLSectorDetail) Or _
            IsNull(Me.txtURLRatingSummary) Or IsNull(Me.txtURLRatingDetail) Then
            Call NullAddProfileMessage
                Exit Sub
ElseIf Me.optIndexMiscel Then
        If IsNull(Me.txtPortfolioCode) Or IsNull(Me.txtPortfolioName) Or _
            IsNull(Me.txtURLSectorSummary) Or IsNull(Me.txtURLSectorDetail) Then
            Call NullAddProfileMessage
                Exit Sub
ElseIf Me.optIndexSFPortfolios Then
        If IsNull(Me.txtPortfolioCode) Or IsNull(Me.txtPortfolioName) Or _
            IsNull(Me.txtURLSectorSummary) Or IsNull(Me.txtURLSectorDetail) Then
            Call NullAddProfileMessage
                Exit Sub
ElseIf Me.optIndexPortMasterStats Then
        If IsNull(Me.txtPortfolioCode) Or IsNull(Me.txtPortfolioName) Or _
            IsNull(Me.txtURLSectorSummary) Then
            Call NullAddProfileMessage
                Exit Sub
End If

End Sub

Open in new window

0
 

Author Closing Comment

by:ssmith94015
ID: 34981160
If I get rid of the intValue and change the IsNull to ="", your code works.  But I will also take a look at the link you provided, thank you!
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
NEED LOOK FOR NUM 23 29
Excel to show a dynamic Picklist at level2 2 23
Userform to show a range in excel. 3 33
Day Count issue - Days360? 12 16
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

732 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