A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Change lblHeading.Caption of report based on which form's buttonclicked



 
 
Thread Tools Display Modes
  #1  
Old May 27th, 2010, 07:26 PM posted to microsoft.public.access
Song[_4_]
external usenet poster
 
Posts: 43
Default Change lblHeading.Caption of report based on which form's buttonclicked

I have 2 separate forms. Button on each form opens a report. One
button on one form says "OPEN" and one button on the other form says
"CLOSE"

I do not want to create one report for each button on separate forms.
I just want to use one report to serve both buttons on different forms

On my report, I have lblHeading. If OPEN button is clicked from one
form, I want to change lblHeading to something. If CLOSE button is
clicked from another from, I want to change lblHeading as well.

Thanks for helping.
  #2  
Old May 27th, 2010, 07:46 PM posted to microsoft.public.access
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default Change lblHeading.Caption of report based on which form's button clicked

What version of Access? Starting in Access 2002 (I believe), the ability to
pass an OpenArgs property was added. Pass anything you want as the OpenArgs
property, and check its value in the report's Open event.

--
Doug Steele, Microsoft Access MVP
http://www.AccessMVP.com/DJSteele
Co-author: Access 2010 Solutions, published by Wiley
(no e-mails, please!)

"Song" wrote in message
...
I have 2 separate forms. Button on each form opens a report. One
button on one form says "OPEN" and one button on the other form says
"CLOSE"

I do not want to create one report for each button on separate forms.
I just want to use one report to serve both buttons on different forms

On my report, I have lblHeading. If OPEN button is clicked from one
form, I want to change lblHeading to something. If CLOSE button is
clicked from another from, I want to change lblHeading as well.

Thanks for helping.



  #3  
Old May 27th, 2010, 07:58 PM posted to microsoft.public.access
Song[_4_]
external usenet poster
 
Posts: 43
Default Change lblHeading.Caption of report based on which form's buttonclicked

Hi, Steele:

I'm using Access 2007. I see OnOpen event of report but I don't know
how to use OpenArgs. I'd be appreciated if you can guide me on this.

Thanks.

Song

On May 27, 11:46*am, "Douglas J. Steele"
wrote:
What version of Access? Starting in Access 2002 (I believe), the ability to
pass an OpenArgs property was added. Pass anything you want as the OpenArgs
property, and check its value in the report's Open event.

--
Doug Steele, Microsoft Access MVPhttp://www.AccessMVP.com/DJSteele
Co-author: Access 2010 Solutions, published by Wiley
(no e-mails, please!)

"Song" wrote in message

...



Hi, Steele:

I have 2 separate forms. Button on each form opens a report. One
button on one form says "OPEN" and one button on the other form says
"CLOSE"


I do not want to create one report for each button on separate forms.
I just want to use one report to serve both buttons on different forms


On my report, I have lblHeading. If OPEN button is clicked from one
form, I want to change lblHeading to something. If CLOSE button is
clicked from another from, I want to change lblHeading as well.


Thanks for helping.- Hide quoted text -


- Show quoted text -


  #4  
Old May 27th, 2010, 08:52 PM posted to microsoft.public.access
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default Change lblHeading.Caption of report based on which form's button clicked

Open the report along the lines of:

DoCmd.OpenReport "NameOfReport", OpenArgs:=Me.Name

Then, in the Open event of the report, check the value passed:

Private Sub Report_Open(Cancel As Integer)

Select Case Nz(Me.OpenArgs, vbNullString)
Case "NameOfForm1"
' do what you want if it was called from Form1
Case "NameOfForm2"
' do what you want if it was called from Form2
Case Else
' do you want to do anything if it was called from somewhere else?
End Select

End Sub

--
Doug Steele, Microsoft Access MVP
http://www.AccessMVP.com/DJSteele
Co-author: Access 2010 Solutions, published by Wiley
(no e-mails, please!)

"Song" wrote in message
...
Hi, Steele:

I'm using Access 2007. I see OnOpen event of report but I don't know
how to use OpenArgs. I'd be appreciated if you can guide me on this.

Thanks.

Song

On May 27, 11:46 am, "Douglas J. Steele"
wrote:
What version of Access? Starting in Access 2002 (I believe), the ability
to
pass an OpenArgs property was added. Pass anything you want as the
OpenArgs
property, and check its value in the report's Open event.

--
Doug Steele, Microsoft Access MVPhttp://www.AccessMVP.com/DJSteele
Co-author: Access 2010 Solutions, published by Wiley
(no e-mails, please!)

"Song" wrote in message

...



Hi, Steele:

I have 2 separate forms. Button on each form opens a report. One
button on one form says "OPEN" and one button on the other form says
"CLOSE"


I do not want to create one report for each button on separate forms.
I just want to use one report to serve both buttons on different forms


On my report, I have lblHeading. If OPEN button is clicked from one
form, I want to change lblHeading to something. If CLOSE button is
clicked from another from, I want to change lblHeading as well.


Thanks for helping.- Hide quoted text -


- Show quoted text -



  #5  
Old May 28th, 2010, 02:31 AM posted to microsoft.public.access
Song[_4_]
external usenet poster
 
Posts: 43
Default Change lblHeading.Caption of report based on which form's buttonclicked

On May 27, 12:52*pm, "Douglas J. Steele"
wrote:
Open the report along the lines of:

DoCmd.OpenReport "NameOfReport", OpenArgs:=Me.Name

Then, in the Open event of the report, check the value passed:

Private Sub Report_Open(Cancel As Integer)

* Select Case Nz(Me.OpenArgs, vbNullString)
* * Case "NameOfForm1"
* * * ' do what you want if it was called from Form1
* * Case "NameOfForm2"
* * * ' do what you want if it was called from Form2
* * Case Else
* * * ' do you want to do anything if it was called from somewhere else?
* End Select

End Sub

--
Doug Steele, Microsoft Access MVPhttp://www.AccessMVP.com/DJSteele
Co-author: Access 2010 Solutions, published by Wiley
(no e-mails, please!)

"Song" wrote in message

...
Hi, Steele:

I'm using Access 2007. I see OnOpen event of report but I don't know
how to use OpenArgs. I'd be appreciated if you can guide me on this.

Thanks.

Song

On May 27, 11:46 am, "Douglas J. Steele"



wrote:
What version of Access? Starting in Access 2002 (I believe), the ability
to
pass an OpenArgs property was added. Pass anything you want as the
OpenArgs
property, and check its value in the report's Open event.


--
Doug Steele, Microsoft Access MVPhttp://www.AccessMVP.com/DJSteele
Co-author: Access 2010 Solutions, published by Wiley
(no e-mails, please!)


"Song" wrote in message


....


Hi, Steele:



I have 2 separate forms. Button on each form opens a report. One
button on one form says "OPEN" and one button on the other form says
"CLOSE"


I do not want to create one report for each button on separate forms.
I just want to use one report to serve both buttons on different forms


On my report, I have lblHeading. If OPEN button is clicked from one
form, I want to change lblHeading to something. If CLOSE button is
clicked from another from, I want to change lblHeading as well.


Thanks for helping.- Hide quoted text -


- Show quoted text -- Hide quoted text -


- Show quoted text -- Hide quoted text -

- Show quoted text -


Got it. If I have 2 items to pass, say heading and subheading, is any
efficient way to do it?
  #6  
Old May 28th, 2010, 01:58 PM posted to microsoft.public.access
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default Change lblHeading.Caption of report based on which form's button clicked

What I typically do is build a string to hold everything. To make it easier,
I'll use something like:

Dim strOpenArgs As String

strOpenArgs = "heading=" & strHeading & ";" & _
"subheading=" & strSubHeading

DoCmd.OpenReport "NameOfReport", OpenArgs:=strOpenArgs

Then, in the Open event of the report, I parse that string:

Private Sub Report_Open(Cancel As Integer)

Dim lngLoop As Long
Dim strHeading As String
Dim strSubheading As String
Dim varArg As Variant
Dim varArgs As Variant

strHeading = "default value"
strSubheading = "default value"

If Len(Me.OpenArgs & vbNullString) 0 Then
' Break the OpenArgs argument into the various parameters
' by splitting on the semi-colons.
varArgs = Split(Me.OpenArgs, ";")
For lngLoop = LBound(varArgs) To UBound(varArgs)
' For each argument, split on the equal sign.
' The name of the argument will be varArg(0),
' the value of the argument will be varArg(1)
varArg = Split(varArgs(lngLoop), "=")
If UBound(varArg) 0 Then
Select Case LCase(varArg(0))
Case "heading"
strHeading = varArg(1)
Case "subheading"
strSubheading = varArg(1)
Case Else
MsgBox "You passed " & varArg(0) & vbCrLf & _
"Sorry: I don't know what to do with " & varArg(0) & "!"
End Select
End If
Next lngLoop
End If

' Check to see whether or not you have values for strHeading
' and strSubheading, and process accordingly.


End Sub


--
Doug Steele, Microsoft Access MVP
http://www.AccessMVP.com/DJSteele
Co-author: Access 2010 Solutions, published by Wiley
(no e-mails, please!)

"Song" wrote in message
...

Got it. If I have 2 items to pass, say heading and subheading, is any
efficient way to do it?

Open the report along the lines of:

DoCmd.OpenReport "NameOfReport", OpenArgs:=Me.Name

Then, in the Open event of the report, check the value passed:

Private Sub Report_Open(Cancel As Integer)

Select Case Nz(Me.OpenArgs, vbNullString)
Case "NameOfForm1"
' do what you want if it was called from Form1
Case "NameOfForm2"
' do what you want if it was called from Form2
Case Else
' do you want to do anything if it was called from somewhere else?
End Select

End Sub




 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:59 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.