cancel
Showing results for 
Search instead for 
Did you mean: 

How to pass the name of an Option Button as parameter to a Stored Procedure?

leon_laikan
Participant
0 Kudos

Hi,

I have created a form with Option Buttons, Edit Boxes and a Combo Box.

The main function of this form is to pass parameters to one or more stored procedures (SQL)

Below is a picture of my form. The names of some of the items are shown.

I can execute a stored procedure and  pass parameters as for example:

StrQuery = "Exec [dbo].[usp_HandOver3]" & "'" & i_Tag & "'" & "," & "'" & oDocCount & "'"

But I don't know how to capture the names of the Option Buttons etc so as to pass them as parameters.

Can anybody help? It may suffice if you outline the main points to be followed.

Thanks

Leon Lai

----------

Accepted Solutions (1)

Accepted Solutions (1)

pedro_magueija
Active Contributor
0 Kudos

Hi Leon,

What do you mean by capturing the "names" of the option buttons? Do you want to know which is selected? Or do you want to know their caption?


Best regards,

Pedro Magueija


View Pedro Magueija's profile on LinkedIn

leon_laikan
Participant
0 Kudos

Hi Pedro,

Thanks for your reply.

Yes, I want to know which button is selected.

For example, if the radio button "OptShip" is clicked, I want to save the string "OptShip" to a variable called "WhichStore". Same for the other buttons in the box.

If the radio button "OptOrig" is clicked, I want to save the string "OptOrig" to a variable called "PrefSortOrder"

There will be 6 variables in all (WhichStore, WhichReport, PrefSortOrder, FromDt, ToDate, Project),

and each variable will contain a value depending on which button, etc is selected.

When I press "Update", this will execute a stored procedure and pass these 6 parameters to it.

Best Regards,

Leon Lai

pedro_magueija
Active Contributor
0 Kudos

Hi Leon,

To check if a option button is selected you can use the property Selected from the SAPbouiCOM.OptionBtn object.

You can either put the value into your variable when you press the Update button (you'll have to check which button is selected), or you can capture the PressedAfter events of the option buttons and fill the variable according to the button that got pressed.


Best regards,

Pedro Magueija


View Pedro Magueija's profile on LinkedIn

leon_laikan
Participant
0 Kudos

Thanks Pedro

I'll work through your suggestion and let you know if I have any problems

Which option: Selected or PressedAfterEvent is easier?

Best Regards,

Leon

pedro_magueija
Active Contributor
0 Kudos

Hi Leon,

I'd personally go with the events. But that's just me.


Best regards,

Pedro Magueija


View Pedro Magueija's profile on LinkedIn

Answers (1)

Answers (1)

edy_simon
Active Contributor
0 Kudos

Hi Leon,

Below are the steps to set up option buttons

I assume I am setting up as below :

1. Create the buttons, either via codes/Screen Painter/B1 Studio.

2. I would name them opt11, opt12, opt13, opt14 and opt21, opt22, opt23, opt24 respectively for group 1 and 2.

3. Add two datasources named "opt1" and "opt2" with datatype short text, size 10

4. Add below code to initialize the options.


                SAPbouiCOM.OptionBtn oOpt = _oForm.Items.Item("opt11").Specific as SAPbouiCOM.OptionBtn;

                oOpt.DataBind.SetBound(true, "", "opt1");

                oOpt.ValOn = "11";

                oOpt = _oForm.Items.Item("opt12").Specific as SAPbouiCOM.OptionBtn;

                oOpt.DataBind.SetBound(true, "", "opt1");

                oOpt.GroupWith("opt11");

                oOpt.ValOn = "12";

                oOpt = _oForm.Items.Item("opt13").Specific as SAPbouiCOM.OptionBtn;

                oOpt.DataBind.SetBound(true, "", "opt1");

                oOpt.GroupWith("opt11");

                oOpt.ValOn = "13";

                oOpt = _oForm.Items.Item("opt14").Specific as SAPbouiCOM.OptionBtn;

                oOpt.DataBind.SetBound(true, "", "opt1");

                oOpt.GroupWith("opt11");

                oOpt.ValOn = "14";

                oOpt = _oForm.Items.Item("opt21").Specific as SAPbouiCOM.OptionBtn;

                oOpt.DataBind.SetBound(true, "", "opt2");

                oOpt.ValOn = "21";

                oOpt = _oForm.Items.Item("opt22").Specific as SAPbouiCOM.OptionBtn;

                oOpt.DataBind.SetBound(true, "", "opt2");

                oOpt.GroupWith("opt21");

                oOpt.ValOn = "22";

                oOpt = _oForm.Items.Item("opt23").Specific as SAPbouiCOM.OptionBtn;

                oOpt.DataBind.SetBound(true, "", "opt2");

                oOpt.GroupWith("opt21");

                oOpt.ValOn = "23";

                oOpt = _oForm.Items.Item("opt24").Specific as SAPbouiCOM.OptionBtn;

                oOpt.DataBind.SetBound(true, "", "opt2");

                oOpt.GroupWith("opt21");

                oOpt.ValOn = "24";

5. The code above will bind the two sets of options with my datasource and group them together.

    I am also giving a value for each of the option button using the oOpt.ValOn property.

6. When the user pressed the update button, you would catch the item pressed event of this update button and review the opt1 and opt2 datasource value.

7.


                System.Diagnostics.Debug.WriteLine(String.Format("Option 1 Value : {0}", _oForm.DataSources.UserDataSources.Item("opt1").ValueEx));

                System.Diagnostics.Debug.WriteLine(String.Format("Option 2 Value : {0}", _oForm.DataSources.UserDataSources.Item("opt2").ValueEx));

8. The datasource opt1 and opt2 should give you the assigned ValOn value of the selected option button.

Good Luck,

Edy

leon_laikan
Participant
0 Kudos

Hi Edy,

Thanks a lot for your answer.

I have already done my homework and marked Pedro's reply as correct when I saw your reply.

Unfortunately, I can only mark one reply as correct.

Best reply

Leon Lai