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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening Query/Reports via Option Groups? 1

Status
Not open for further replies.

Nokus

Technical User
Nov 28, 2006
5
GB
Hi, I'm wondering if it's possible to use Option groups (Or Radio buttons to be pedantic) to open Queries or Reports in the database? And if it can, how can one go about coding it?

Screenshot

What I want to do is click on the Query or Report option then click on one of those options to the right and that'll open up the saved query or report.

I tried using command buttons but they just bloated the screen up.
 
You can use an appropriate event, say After Update or Click, and Select Case. I am quite fond of combo boxes for listing reports.

 
So I have to go into VBA from one of those Event options then?

Can you point me in the direction of any code for it? When I learnt Access it was all via the front end and none of this VBA background stuff.

*wishes he paid more attention to those VB lessons at College*
 
Sneak code from the wizard code for open form and open report. Set the name of the document to open in a Select Case statement. Use the After Update event of the Option Frame. Tack something together and post it back.

Combos are easier because you can use several columns, which reduces the code needed to a few lines.
 
How are ya Nokus . . .

Agree with [blue]Remou[/blue]! In a combobox/listbox you could [blue]include the actual query/report names in hidden columns[/blue] (makes for easier execution in code instead of having to lookup the names).

[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .
 
Something like this?

Query/Report selection:
Code:
Private Sub Frame2_AfterUpdate()
 Dim Frame2 As Integer
Select Case Frame2
Case 1
    DoCmd.OpenQuery stDocName, acViewNormal
Case 2
    DoCmd.OpenReport stDocName, acPreview
End Select
End Sub

Query/Report files:
Code:
Private Sub Frame9_AfterUpdate()
Case 3
    Dim stDocName As String
        stDocName = "Day"
Case 4
    Dim stDocName As String
        stDocName = "Start Time"
End Sub

Like that?
 
That's looking good.

Put
Dim stDocName As String
At the very top of the code, just under Option Explicit, to make it available to all procedures in this module.

Move this code to the open button:
Code:
[s]Private Sub Frame2_AfterUpdate()
 Dim Frame2 As Integer[/s]
If Trim(stDocName & "")="" Then
    MsgBox "Nothing to do"
    Exit Sub
End If

Select Case Frame2
Case 1
    DoCmd.OpenQuery stDocName, acViewNormal
Case 2
    DoCmd.OpenReport stDocName, acPreview
Case Else
    MsgBox "Please pick query or report"
End Select
End Sub

Code:
Private Sub Frame9_AfterUpdate()
Case 3
    [s]Dim stDocName As String[/s]
        stDocName = "Day"
Case 4
    [s]Dim stDocName As String[/s]
        stDocName = "Start Time"
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top