|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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. |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
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 |
|
#5
|
|||
|
|||
|
I tried something similar to this but couldnt get it to work. Thanks for your help!
|
![]() |
| Viewing: Dev Articles Community Forums > Databases > Microsoft Access Development > Pass variable Form data to a Report |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|