Solved

Determine which value is selected in an Excel form option group

Posted on 2011-02-25
2
232 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

726 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