Microsoft Access Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft Access Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old August 18th, 2005, 02:42 PM
br_esper br_esper is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 23 br_esper User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 55 m 14 sec
Reputation Power: 0
Pass variable Form data to a Report

Does anyone know if it is possible to pass a value from a form into a label, or text box in a report?

I have a form that I request a date range from the user. This date range is passed as variables to the function that my report is tied to. I would like the date range to be displayed at the top of the report like: For Period 08/01/2005 - 08/31/2005

Reply With Quote
  #2  
Old August 18th, 2005, 05:14 PM
br_esper br_esper is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 23 br_esper User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 55 m 14 sec
Reputation Power: 0
OK, I found a way to do it but it isn't exactly what I was thinking. But hey...it works.
-------------------FORM CLICK EVENT-------------------
For the Forms Report Button Click Event I setup the OpenReports OpenArg string with data from the form

'---First, get data from the Date fields on the form---
strArg = "For Period " + Str(tbBeginDate) + " - " + Str(tbEndDate) + ";"
'---Next, check to see if a Client was seleted from the combo box, if yes then add it to the strArg
If cbClient.Value <> "" Then
strArg = strArg + "Client: " + cbClient.Value + ";"
End If

'---Call the report and pass the strArg as the OpenArg parm
DoCmd.OpenReport "Rpt_fn_AccountSummary", acViewPreview, , , acWindowNormal, strArg

-----------REPORT OPEN EVENT-------------------------
On the report open event I parse the argument passed into the appropriate labels captions. I use the ";" to separate the arguments passed to the report

Private Sub Report_Open(Cancel As Integer)
Dim intx As Integer, intxSave As Integer
Dim strOpenArg As String

strOpenArg = Me.OpenArgs
intx = InStr(1, strOpenArg, ";")
If intx <> 0 Then
lblPeriod.Caption = Mid$(strOpenArg, 1, intx - 1)
intxSave = intx + 1
intx = InStr(intx + 1, strOpenArg, ";")
If intx <> 0 Then
intLen = intx - intxSave
lblClient.Caption = Mid$(strOpenArg, intxSave, intLen - 1)
Else
lblClient.Caption = ""
End If
Else
lblPeriod.Caption = "No Period Selected"
lblClient.Caption = ""
End If
End Sub


----------------------------------------------------
Even though this works, I was really looking for a way to directly reference the form values on the report.

Reply With Quote
  #3  
Old August 19th, 2005, 08:21 AM
sherrington sherrington is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 85 sherrington User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 4 m 52 sec
Reputation Power: 5
Assuming the form is still open when the report is open then create a text box on the report and set its control source to:

=Forms!FormName!ControlName

Reply With Quote
  #4  
Old August 19th, 2005, 08:42 AM
lwells lwells is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Sep 2004
Posts: 632 lwells User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 21 h 59 m 38 sec
Reputation Power: 5
Hi br esper,



If your form remains open when you open your report, you can call the forms control values directly into the report labels.

In your Report Open Event using something like this:



If Not IsNull(Forms![FormName].tbBeginDate) And Not IsNull(Forms![FormName].tbEndDate) Then

lblPeriod.Caption = “For Period “ & Forms![FormName].tbBeginDate & “ – “ & Forms![FormName].tbEndDate

Else

lblPeriod.Caption = “No Period Selected”

End If



If Not IsNull(Forms![FormName].cbClient) Then

lblClient.Caption = “Client: “ & Forms![FormName].cbClient

Else

lblClient.Caption = “ “

End If



If your form closes when opening the report then use your OpenArguments

lwells

Reply With Quote
  #5  
Old August 19th, 2005, 01:17 PM
br_esper br_esper is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 23 br_esper User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 55 m 14 sec
Reputation Power: 0
I tried something similar to this but couldnt get it to work. Thanks for your help!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft Access Development > Pass variable Form data to a Report


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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 On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT