Wrong report titles

N

none

I have a report that is supposed to pull up the title from the VBA
code within the report and form that calls out the report. However,
when I click on the button on the form to generate the report, the
report title is always "lagging" one click behind (for example, the
title for the report for "Title A" has no title, when I click on
report "Title A" again then it takes on "Title A"; if I then chose
report "Title B", it calls out the correct data but retains the "Title
A".)

On the form, I have the following code:
===
Private Sub optnSpeakers_MouseDown(Button As Integer, Shift As
Integer, X As Single, Y As Single)
'OptList =1
DoCmd.Close acReport, "rList"
DoCmd.OpenReport "rList", acViewPreview, , "[Batch]=0"

End Sub

Private Sub optbSponsors_MouseDown(Button As Integer, Shift As
Integer, X As Single, Y As Single)
'OptList =2
DoCmd.Close acReport, "rList"
DoCmd.OpenReport "rList", acViewPreview, , "[Batch]=97"

End Sub

Private Sub optnParticipants_MouseDown(Button As Integer, Shift As
Integer, X As Single, Y As Single)
'OptList =3
DoCmd.Close acReport, "rList"
DoCmd.OpenReport "rList", acViewPreview, , "[Batch]=500 or
[Batch]=99"

End Sub
====

In the rList report, I have the following code:
===
Private Sub Report_Open(Cancel As Integer)

If Forms!rListsSwitchboard.optList = 1 Then
Me.Caption = "Title A"
Me.lblReportName.Caption = "Title A"

ElseIf Forms!rListsSwitchboard.optList = 2 Then
Me.lblReportName.Caption = "Title B"
Me.Caption = "Title B"

ElseIf Forms!rListsSwitchboard.optList = 3 Then
Me.lblReportName.Caption = "Title A"
Me.Caption = "Title B"

End If
End Sub
====

Am I using the wrong action/function? What should I be using instead?

Thank you for your help!
 
D

Dirk Goldgar

none said:
I have a report that is supposed to pull up the title from the VBA
code within the report and form that calls out the report. However,
when I click on the button on the form to generate the report, the
report title is always "lagging" one click behind (for example, the
title for the report for "Title A" has no title, when I click on
report "Title A" again then it takes on "Title A"; if I then chose
report "Title B", it calls out the correct data but retains the "Title
A".)

On the form, I have the following code:
===
Private Sub optnSpeakers_MouseDown(Button As Integer, Shift As
Integer, X As Single, Y As Single)
'OptList =1
DoCmd.Close acReport, "rList"
DoCmd.OpenReport "rList", acViewPreview, , "[Batch]=0"

End Sub

Private Sub optbSponsors_MouseDown(Button As Integer, Shift As
Integer, X As Single, Y As Single)
'OptList =2
DoCmd.Close acReport, "rList"
DoCmd.OpenReport "rList", acViewPreview, , "[Batch]=97"

End Sub

Private Sub optnParticipants_MouseDown(Button As Integer, Shift As
Integer, X As Single, Y As Single)
'OptList =3
DoCmd.Close acReport, "rList"
DoCmd.OpenReport "rList", acViewPreview, , "[Batch]=500 or
[Batch]=99"

End Sub
====

In the rList report, I have the following code:
===
Private Sub Report_Open(Cancel As Integer)

If Forms!rListsSwitchboard.optList = 1 Then
Me.Caption = "Title A"
Me.lblReportName.Caption = "Title A"

ElseIf Forms!rListsSwitchboard.optList = 2 Then
Me.lblReportName.Caption = "Title B"
Me.Caption = "Title B"

ElseIf Forms!rListsSwitchboard.optList = 3 Then
Me.lblReportName.Caption = "Title A"
Me.Caption = "Title B"

End If
End Sub
====

Am I using the wrong action/function? What should I be using instead?


It looks to me like you're using the wrong event. In the MouseDown event of
a control, the value of the control hasn't been updated yet. It would make
more sense, at least to me, to use your option group's AfterUpdate events.
When that fires -- and remember that the value of an option group can be
changed via the keyboard, without even touching the mouse -- you know that
the control's value has been changed.

Are optnSpeakers, optbSponsors, and optnParticipants all individual options
within the option group optList? If so, you might drop the MouseDown
procedures for them and use this event procedure for the option group
itself:

'----- start of example code -----
Private Sub optList_AfterUpdate()

Dim strCriteria As String

Select Case Me.optList

Case optnSpeakers.OptionValue ' or Case 1
strCriteria = "[Batch]=0"

Case optbSponsors.OptionValue ' or Case 2
strCriteria = "[Batch]=97"

Case optnParticipants.OptionValue ' or Case 3
strCriteria = "[Batch]=500 Or [Batch]=99"

Case Else
' unknown or unspecified option.
Exit Sub

End Select

DoCmd.Close acReport, "rList"
DoCmd.OpenReport "rList", acViewPreview, , strCriteria

End Sub

'----- end of example 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

Top