 |
| Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

June 20th, 2006, 04:16 AM
|
|
Friend of Wrox
|
|
Join Date: Dec 2005
Posts: 233
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Opening Using Option Button
hi friends,
It is Possibel to Open an from or a Report by selecting in Option Button.. i.e. For eg
Two Names Total Report and User Customize Report. Total report is for Opening the Total Report View and User Customize Report is user can customezies the report by what data they desire.
I want to use an Option Button as for Total Report and user Customize report and command button to executed the function..as when i select the total report then the total report view will get the data and when i chose the user customize report then the customize report from should open..
is it possible for me to get the data like that ..pls give me an solution
bye
------------------------
pap...
|
|

June 20th, 2006, 07:14 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
I use option groups to save values to tables, but I am not sure where you would get the selection value if you wanted to pass it to a command button. Can you use a button for the total report, and then some controls for the user to modify the report as they need to on the same form?
mmcdonal
|
|

June 20th, 2006, 11:54 AM
|
|
Friend of Wrox
|
|
Join Date: Dec 2005
Posts: 142
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
In the On Click event for the command button, use the following code to take options from an Option Group:
Select Case [Forms]![frmMainMenu]![OptionGroupName]
Case 1
Call Function1()
Case 2
Call Function2()
End Select
Put the code for Function1, Function2, etc. (have as many as you want, can also use parameters if the code is similar between options) in a module called Program Functions.
|
|

June 20th, 2006, 11:55 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
|
|
Well, the option button would give you either a 1 or 2 depending on which option you chose. On the option group's After Update event, you can say something like (I'm using fake names for stuff).
Dim strReport as String
If Me.grpMyOptionGroupName = 1 Then
strReport = "rptTotal"
Else
strReport = "rptUserCustomize"
End If
DoCmd.OpenReport strReport, acPreview
However, if you want to open the report that the option group is ALREADY sitting on, it won't open unless you pick the other one then come back. That's a pain. In that case, I would not put anything on the option group's After Update event. I would put a button next to it and then put that code on the button's On Click event. So you'd pick an option or leave it where it's sitting, then click the nearby button.
Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
|
|

June 21st, 2006, 01:34 AM
|
|
Friend of Wrox
|
|
Join Date: Dec 2005
Posts: 233
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hi,
kindler wat do u mean of creating an program function if , chosse function like that ..plz give me an idea and clarify my doubt...
bye
------------------------
pap...
|
|

June 21st, 2006, 12:27 PM
|
|
Friend of Wrox
|
|
Join Date: Dec 2005
Posts: 142
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Alt-F11 to open VBA
In Project window (top right pane by default)
-Right click on database name
-Click Insert->Module
-New window opens by default
In that window enter as many subroutines or functions as you need. You probably don't need functions for what you are trying to do, the code would look something like this in the On Click event for the command button.
Select Case [Forms]![frmMainMenu]![OptionGroupName]
Case 1
CoCmd.OpenReport "rptTotal", acPreview
Case 2
DoCmd.OpenForm "frmCustomizeReport"
End Select
|
|

June 22nd, 2006, 01:36 AM
|
|
Friend of Wrox
|
|
Join Date: Dec 2005
Posts: 233
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
kind,
I understand plz explain me what is the relation between the case and the option group.. becaz how can it works with option group..plz don't get hot ..plz plz explain..
bye
------------------------
pap...
|
|

June 22nd, 2006, 01:51 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
|
|
Hi Pap,
I am about to logoff for the night, but hopefully this can lead you in the right direction.
In an option group, you would assign each radio button a value, lets say 1, 2 and 3 for example. You can now do a Select Case on the value of the option group, and your Case statements would be executed, depending on which radio button was selected.
Hope that helps.
Mike
Mike
EchoVue.com
|
|

June 23rd, 2006, 04:02 AM
|
|
Friend of Wrox
|
|
Join Date: Dec 2005
Posts: 233
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
give me an example wat u said above...plz
bye
------------------------
pap...
|
|

June 23rd, 2006, 07:10 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
What you would do is create the option group using the wizard. This will allow you to create labels for each option, and assign numeric values to each option selection, generally 1, 2, 3.
Once you have done this, create a button, and for the button's On Click event, use SerranoG's code to take a value from the Option Group. Based on the value, you select the report you want to run.
You may want to change the code slightly like this:
Dim sReport As String
Dim sForm As String
sReport = "rptYourReportName"
sForm = "frmYourCustomizeReportFormName"
If Me.grpMyOptionGroupName = 1 Then
DoCmd.OpenReport sReport
Else
DoCmd.OpenForm sForm
End If
This way, if they want the basic report, they make that selection and open the report. If they want to customize the report, they make that selection from the option group and open the customize report for, which then has your customization controls and a button to open the customized report.
This is all kind of the long way around since you can have a report button on the first form, then customization controls on the same form with a button to open the customized report. But space may be at a premium and a second form is needed?
Does this help?
mmcdonal
|
|
 |