Options controls

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello. I'm triyng to use two Option controls to define what report should it
print when press the Print button. I'm using the following code:

Dim mapa1 As String
Dim mapa2 As String

If Option23.OptionValue = 1 Then GoTo mapa1
If Option25.OptionValue = 2 Then GoTo mapa2


mapa1:
mapa1 = "rpt_ControloCustos_NotaProducao"
DoCmd.OpenReport mapa1, acPreview

mapa2:
mapa2 = "rpt_ControloCustos_ProdutoAcabado"
DoCmd.OpenReport mapa2, acPreview

This code print both reports.

Can anyone help me?
Marco
 
I would suggest staying away from GoTo statements. You should put your option
buttons inside an option group. Then you can evaluate the value of the group
control. You can the use a Select Case to branch the code. Make sure the
option values of the two buttons are 1 and 2.

Select Case Me.grpPrintOption 'the name of the option group control.
Case 1
DoCmd.OpenReport "rpt_ControloCustos_NotaProducao", acPreview
Case 2
DoCmd.OpenReport "rpt_ControloCustos_ProdutoAcabado", acPreview
End Select

Barry
 
You could also try something like this.

Private Sub Option23_AfterUpdate()
If Me.Option23= True Then
Me.Option25= False
End If
End Sub

Private Sub Option25_AfterUpdate()
If Me.Option25= True Then
Me.Option23= False
End If
End Sub

Private Sub cmbPrint_Click()
If Me.Option23 = True Then
DoCmd.OpenReport "rpt_ControloCustos_NotaProducao", acNormal
Else
If Me.Option25 = True Then
DoCmd.OpenReport "rpt_ControloCustos_ProdutoAcabado", acNormal
Else
MsgBox "You must make a choice."
End If
End If
End Sub
 
Marco said:
Hello. I'm triyng to use two Option controls to define what report should it
print when press the Print button. I'm using the following code:

Dim mapa1 As String
Dim mapa2 As String

If Option23.OptionValue = 1 Then GoTo mapa1
If Option25.OptionValue = 2 Then GoTo mapa2


mapa1:
mapa1 = "rpt_ControloCustos_NotaProducao"
DoCmd.OpenReport mapa1, acPreview

mapa2:
mapa2 = "rpt_ControloCustos_ProdutoAcabado"
DoCmd.OpenReport mapa2, acPreview

This code print both reports.


That's another reason to avoid using the GoTo statement.

Your code looks like you are using an Option Group
containing the option buttons. With this arrangement you
can only select one option in the group and the could be
more like:

Dim strMapa As String

Select Case Me.optiongroup
Case 1
strMapa = "rpt_ControloCustos_NotaProducao"
Case 2
strMapa = "rpt_ControloCustos_ProdutoAcabado"
End Select
DoCmd.OpenReport strMapa, acPreview

On the other hand, if you have the option buttons directly
on the form (not in an option group), then you can select
multiple options and the code could be like:

Dim strMapa As String

If Me.Option23 Then
strMapa = "rpt_ControloCustos_NotaProducao"
DoCmd.OpenReport strMapa, acPreview
End If
If Me.Option25 Then
strMapa = "rpt_ControloCustos_ProdutoAcabado"
DoCmd.OpenReport strMapa, acPreview
End If

Note the complete absence of GoTo in all of the above code.
 

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

Back
Top