Link Option Group to Command Button

Brainwave

New member
Local time
Today, 01:48
Joined
Jul 18, 2008
Messages
3
I actually have two questions.
(1) I have an option group with four reports in a form. I wand to add a preview button and a print button that will open each report as they are selected. I followed Access 2003 help info and it did not work. How do I accomplish this simple task?
(2) In that same database, I have another form with a combo box and about nine selections. Four of these selection open a separate form to add info related to the selection. That works great. However, the other five items do not have to have a separate form. When selected the user should be able to go to the next field in the form. Here is the code:

Private Sub Item_Change ()
If ([Item] = "Computer") Then
DoCmd.OpenForm "Computer"
Else
If ([Item] = "Vehicles") Then
DoCmd.OpenForm "Vehicles"
Else
If ([Item] = "Furniture") Then
DoCmd.OpenForm "Furniture"
Else
If ([Item] = "Cell Phones") Then
DoCmd.OpenForm "Cell Phones"
Else
If [Item] = "table" Then
DoCmd.OpenForm "Form"
End If
End If
End If
End If
End It
End Sub
I have it tabbed, but the post untabbed it. I don't know if the word "table" is correct to proceed to the next field. I am new to VBA.
 
First, instead of multiple If/Then, which can get awkward fast, try this:

Code:
Select Case Item
    Case 1
        Docmd.OpenForm "Computer"
    Case 2
        Docmd.OpenForm "Vehicles"
    Case Else
        'Do Nothing
End Select

Secondly, I'm pretty sure Option Group return only an integer, not a string, so you can't use "Computer" as comparison, but rather the integer that is given whenever the option "Computer" is selected.

Tangentially, to post a code, use the tags [code]Your Code here[/code] to get the formatting preserved:
Code:
Your Code Here
 
I tried the above and it did not work. The forms that opened before won't open. The option group has four reports with a radio button. I'd like the print or preview button to open whichever report is selected. How would I do this without creating four separate command buttons.

I got it working with my original code, but just added another if then and else statement with 'Do Nothing. That works great. Thanks!
 
Last edited:
Are you sure the Option Group is giving out a integer? If nothing happened, it may be that Option Group wasn't set up right?

To verify, step through the VBA code and check if Item even has a value at all. If you don't know how to step through, click the link in my siggy below which gives examples of how to do so.
 
I was not specific in my question. The VBA code has nothing to do with the option group. I just opened an unlinked blank form in design mode and added the option group. Then, I wanted to add two command buttons to the side of the group that would either open or preview the report that is selected with the radio button. Sorry for the confusion. I still haven't figured out how to accomplish this task.
The form has four report names listed with radio buttons to the left.
 
Here is a response that Bob Larson gave me for a similar problem. It works well for me.

For future reference, I think I would make it easier on yourself by using a listbox which can AUTOMATICALLY list all reports available, so you never need update the controls on the form and you can let it be a multi-select listbox so you can iterate through and print all of the selected reports.

Check out this sample of mine as to the dynamic report list:
http://downloads.btabdevelopment.com...rtFromForm.zip

it doesn't currently do multiple reports but it could.
 

Users who are viewing this thread

Back
Top Bottom