Option Groups

C

Crazy Lady

I need to set up Print and Preview Command Buttons associated with an option
group (with 3 options). The options relate to reports set up to show
information relating to different clients.

I checked to see how it was done in Northwind, but when I tried to create
the same On Click Event Procedure (replacing the object names appropriately),
Access debugged OK but then when I tryto select from the option group and use
the command buttons nothing happens. It would be easier to set up 3
different pairs of command buttons.
 
N

Nikos Yannacopoulos

Can't guess what you might be doing wrong without knowing the details of
the option group and your code; post them if you wish.

If you want to see an alternative option, namely selecting the report
from a listbox, look for a post titled "Command button report selection"
posted on May 23 in the Reports group; my answer to that one explains
how to do it.

HTH,
Nikos
 
C

Crazy Lady

Can't find "Command button report selection" even though I did a search.

I have an option group with 3 options that I want to link to 3 reports. The
first is "CompanyName Maintenance", the second is "Company name Projects",
the third is "Others".

From the Northwind "Sales by ..." procedure I have taken:

Option Compare Database 'use database order for string comparison.
Option Explicit 'Requires variables to be declared before they are used.Sub
PrintReports (PrintMode As Integer)

On Error GoTo Err_Preview_Click
'This procedure used inh Preview_Click and Print_Click Sub procedures.
'Preview or Print repor selected in the InvoiceType option group.
'Then close the Print Sales Reports Dialog form.

Select Case Me!ReportToPrint
Case 1
DoCmd.OpenReport "Company Name Maintenance", PrintMode
Case 2
DoCmd.OpenReport "Company Name Projects", PrintMode
Case 3
DoCmd.OpenReport "Others", PrintMode
End Select
DoCmd.Close acForm, "InvoiceType)

Exit_Preview_Click:
Exit Sub
Err_Preview_Click:
Resume Exit_Preview_Click

End Sub

Private Sub Cancel_Click()
'this code created by Command Button Wizard.
On Error GoTo Err_Cancel_Click

'Close form.
DoCmd.Close

Exit_Cancel_Click:
Exit Sub

Err_Cancel_Click:
MsgBox Err.Description
Resume Exit_Cancel_Click

End Sub

Private Sub Preview_Click()
'Preview selected report. This procedure uses the PrintReports
'Sub procedure defined in (General) section of this module.

PrintReports ac Preview

End Sub

Private Sub Print_Click()
'Print selected report. This procedure uses the PrintReports
'Sub procedure defined in (General) section of this module.

PrintReports acNormal

End Sub

This is almost exactly as the Northwind sample, but missing out references
to their Select Category bit since I have not chosen to have a selection from
"others".

- Crazy Lady
 
C

Crazy Lady

Sorry Nikos, I have found Command Button Report Selection. I'll give this a
try first and respond to you.
thanks
-Crazy Lady
 
C

Crazy Lady

I seem to have no idea what the heck I am supposed to be doing. The list box
came up OK but the command button wizard still wants to connect to only one
report and forces you to choose one. OK, so you can change the module that
is automatically written, but
1) what exactly should be taken out and what should be left in, and
2) the underline character in you code seems to be an invalid character, nor
did the debugger like the & character, saying that it expected a line number.

I don't find the list/combo box aesthetically pleasing so I would prefer to
go back to my original plan to use an Option Group with Preview and Print
Buttons.

Please bear in mind that I am a complete novice with visual basic - it must
be 20 yrs since I wrote some little programs on a BBC Electron or Micro! At
least the manual with those listed available commands and syntax, though.
Here, I'm totally lost.

Please be patient with me. Thanks
- Crazy Lady
 
N

Nikos Yannacopoulos

I'm not familiar with Northwind, but if you are not getting an error
message at all, my best guess is the option group is not actually
returning a value between 1 and 3, so no branch of the Select case
executes. Insert a line of code like:

MsgBox Me!ReportToPrint

right before the Select Case Me!ReportToPrint statement, so you see what
is being returned.

HTH,
Nikos
 
C

Crazy Lady

Hi Nikos,

I started all over again, renamed my form and option group, re-typed the
code (including your addition) and Bingo!

Thanks for your help, - I'll be back!

- Crazy Lady
 
N

Nikos Yannacopoulos

I understand you've solved it by now, but for what it's worth:
The list box came up OK but the command button wizard still wants to
connect to only one report and forces you to choose one.
Let it do what it wants. then just throw away everything between the Sub
declaration and End lines, and paste your code in between. Even
better, just cancel out as soon as the wizard opens, then all you're
left with are the Sub start and end lines.

2) the underline character in you code seems to be an invalid character, nor
did the debugger like the & character, saying that it expected a line number.
I suppose you are referring to an underscore here... the problem is not
the character itself, it is that sometimes when pasting code into a
newsgoup post and then from there into a VBA module, soft returns are
made hard; to fix that, the easiest way is to put long expressions in
one line, and then, if you want, split them up again across several
lines within the VBA editor.

I don't find the list/combo box aesthetically pleasing so I would prefer to
go back to my original plan to use an Option Group with Preview and Print
Buttons.
I won't argue on that, it's subjective anyway. The merit of this
approach is not aesthetic, it's the fact that it requires no design
changes if you add or remove reports.

Please bear in mind that I am a complete novice with visual basic - it must
be 20 yrs since I wrote some little programs on a BBC Electron or Micro!
I can understand where you're coming from, I started with Fortran 77 on
a Univac mainframe, and moved on to a ZX Spectrum! Object oriented
programming is a different animal though.

Come back if you need help.

Nikos
 
C

Crazy Lady

Thanks for all your help Nikos. I'm on the last lap with this project now,
but it could be the trickiest for me. I'm sure I'll be back for more help.
Thanks again.

- Crazy Lady
 
N

Nikos Yannacopoulos

Welcome!

Crazy said:
Thanks for all your help Nikos. I'm on the last lap with this project now,
but it could be the trickiest for me. I'm sure I'll be back for more help.
Thanks again.

- Crazy Lady

:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top