Solved

Determine which value is selected in an Excel form option group

Posted on 2011-02-25
2
224 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
2 Comments
 
LVL 18

Accepted Solution

by:
WarCrimes 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

760 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