Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Option Groups

Status
Not open for further replies.

akins4lyfe

Programmer
Oct 6, 2010
39
GB
Hi,

I have a form containing 5 option buttons, to check for series of specific validities, 1 command button, and a text box to display validity notes.

I would like a user to select an option by checking the option buttons, then click on the command button, and place a note inside the text box available on my form. An option must to be selected, it's compulsory.

Depending on the option selected by the user, there are different notes available for each options.

Now, here is the problem, the first option works fine, when selected, and the command button clicked to generate a note. But the rest are not working. I have posted my code below, for any suggestions, critics & corrections pls.

If Me.OptionValid90.Value = True Then
Me.txtNote "Welcome on board"
ElseIf Me.OptionValid28.Value = True Then
Me.txtNote = "Valid for 28 days only"
ElseIf Me.OptionInvalid.Value = True Then
Me.txtNote = "Your subscription is Invalid"
ElseIf Me.OptionInvalidV6.Value = True Then
Me.txtNote = "V6 Validity"
ElseIf Me.OptionManagerAuth.Value = True Then
Me.txtNote = "Authorisation Required"
Else
Me.txtNote = ""


Thank you all.
:)
 
i have now resolved this, by assigning an operator to line 2

here:
Me.txtNote "Welcome on board"

corrected as :
ME.txtNote = "Welcome on board"

Thanks
 

Jusk a quick note - since only one option button can be selected at any given time, you may re-write you code to be:
Code:
Select Case True
    Case Me.OptionValid90.Value
        Me.txtNote = "Welcome on board"
    Case Me.OptionValid28.Value 
        Me.txtNote = "Valid for 28 days only"
    Case Me.OptionInvalid.Value
        Me.txtNote = "Your subscription is Invalid"
    Case Me.OptionInvalidV6.Value 
        Me.txtNote = "V6 Validity"
    Case Me.OptionManagerAuth.Value 
        Me.txtNote = "Authorisation Required"
    Case Else
        Me.txtNote = ""
End Select
It is a lot easier to read, at least to me :)

Have fun.

---- Andy
 
hi Andy,

Thanks for sharing that neat trick, Now, what if i am selecting more than one option, at a time? for example up to 5 options. Any clue as to how series of results may be generated?

 
this has just been resolved, i tried something along this line,

Select Case True
Case Me.OptionTerminate1.Value And Me.OptionOther1
Me.txtNote = Tc1 &" "& Other1
End Select

Where Tc1 and Other1 are variables, with different values assinged.

And it worked, perfectly!
 
selecting more than one option
Now you are breaking the rules of how Windows' controls should work.

if you have a group of option buttons, only one can be selected.

If you want to select muliple 'option buttons', they have to be in separate groups. Or choose Check Boxes instead - none, one, many, or all could be selected.

Don't confuse the Users :)

Have fun.

---- Andy
 
Oh yes, absolutely correct, i have multiple 'option buttons' and they are all in separate groups.

See, the problem with Check boxes is this, there's no way to code the "Onclick" Event of a check box. That would have been the smartest way of doing things.

Well, problem solved now :)

Thanks
 
>no way to code the "Onclick" Event of a check box

There isn't?
 

i have multiple 'option buttons' and they are all in separate groups.
Oh, good.
But I would not code it like this - picking selection from different groups:
[tt]
Select Case True
Case Me.OptionTerminate1.Value And Me.OptionOther1
Me.txtNote = Tc1 & " " & Other1
End Select
[/tt]
because you code will grow exponentially, more options = A LOT more possibilities = a nightmare in the code.

Try something like:
Code:
Dim Tc1 As String
Dim Other1 As String

Select Case True[green]
    'Deal with group 1[/green]
    Case Me.OptionValid90.Value
        Tc1 = "Welcome on board"
    Case Me.OptionValid28.Value 
        Tc1 = "Valid for 28 days only"
    Case Me.OptionInvalid.Value
        Tc1 = "Your subscription is Invalid"
End Select

Select Case True[green]
    'Deal with group 2[/green]
    Case Me.OptionInvalidV6.Value 
        Other1 = "V6 Validity"
    Case Me.OptionManagerAuth.Value 
        Other1 = "Authorisation Required"
End Select

Me.txtNote = Tc1 & " " & Other1

No need for [tt]Case Else[/tt] since option buttons should always have something chosen by default - IMO.

Have fun.

---- Andy
 
@dhookom.

I decided to nest my data inside my codes because of the following reasons:

I have series of notes that needed to be concatenated together with sets of other values, to produce dynamic results. For example current date, current time, 5point signatures of different employee across different regions & from various departments. These changes constantly almost every day.

I agree Some of these could reside perfectly inside a relation. But not when datas are constantly changing.

Thanks
 
And I still can't understand why we are using option buttons instead of checkboxes
 
@dhookom yeah, i know that, not a common or best way of doing things. But what you have to understand is this, the main purpose of this project is to create "new notes" ...something like an "Auto Noter", whereby entries by a user changes every minute.

So, what i did was to collect those entries, through text boxes on a form, select relevant option to those entries, click a button, merge all those details together into one standard "Note" for a user to further apply onto another in-house system.

Now, you have a very good point, about storing data inside a table, but in this case, it just won't work. Otherwise i'll have to do a Maketable and Append Query within my project, which will create and append new table, each time a user enters a value via a textbox.

Doing this will result in thousands of tables been created, within minutes, as this application is shared over a very large network.

Furthermore, i am not really using recordsets in saving and retaining any values, all i am doing is collecting series of data through a form, merging those with the standard ones nested within my code, selecting an option on the form, and populating series of textboxes and lists boxes.

Pretty simple project. But, yeah, thanks a lot for your advice. I do know that's the best way of working with data.

@strongm(MIS)

I think option buttons is the most suitable, in this case, so i decided to use them. Please bear with my programming skills, :) just fresh from university, new to VBA, so i am still learning and gaining new skills.

Thank you all.

:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top