Solved

Determine which value is selected in an Excel form option group

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Vlookup - 2 criteria 6 43
Formula fix for vlookup and iserror 3 23
Excel formula that pulls back the id 4 39
Conditional fromatting formula 29 29
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
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…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

679 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