As always, you ask a question and get more than you bargained for. That
Split function is a completely new trick for me. More study...
Q4: I thought I typed more than appears on my post; anyway, the point I was
making is that earlier in our thread you guided me about passing openArgs to
the report. then you said this:
"On the OnPrint event of the section where the text box located write the code
Me.[TextBoxName]= Me.OpenArgs"
My assumption at the time was that without this code the header would appear
in print preview but not print off. I haven't yet entered this code, but the
report printed ok, header and all. So I'm not sure what the code is for.
I have one more related problem (I appreciate your time and help - if I'm
taking up too much of it let me know and I'll post as a new thread)
Some of my existing reports require filtering for a particular month. I'm
testing a copy of one and can't get the WHERE clause to filter properly (no
error messages, just wrong data).
My idea was to define strDate1 and strDate2 as the first and last days of
the month and use these to set the filter string. The result seems to be a
filter on one side and not the other (eg for a student who started in January
I get January to March when I choose March, and January to april when I
hcoose April.)
Code follows:
Private Sub cmdPreview_Click()
'Opens the named report with selected filters.
'Closes the prompt form.
Dim strReportName As String 'The report to be opened
Dim strPromptForm As String 'The name of the prompt form.
Dim strWhere As String 'The filter string
Dim strDate, strDate1, strDate2 As String 'The date filters -
'to be added to strWhere
Dim intMonth, intYear As Integer 'The month and year filters
Dim strReportHeader, strDateHeader As String
'The strings used to build the report
header (OpenArgs)
strReportName = "rptTrial1"
strPromptForm = "frmTrial2_Prompt"
intMonth = Me.cboMonth
intYear = Me.txtYear
strDate1 = DateSerial(intYear, intMonth, 1) '(first day of the month)
strDate2 = DateSerial(intYear, intMonth + 1, 1) - 1 '(last day of the month)
'Set the date filter and date header string
If IsNull(cboMonth) = False Then
strDate = "tblLessons.dtTransactionDate >= #" & strDate1 & _
"# And tblLessons.dtTransactionDate <= #" & strDate2 & "#"
strDateHeader = Me.cboMonth.Column(1) & " " & Me.txtYear
End If
'Set the student and date filters
If IsNull(cboStudentName) = False Then
strWhere = "tblStudents.intStudentID = " & cboStudent
End If
If strDate <> "" Then
strWhere = strWhere & " and " & strDate
End If
'Create the report header
strReportHeader = "Student summary for " & Me.cboStudent.Column(2) _
& " " & Me.cboStudent.Column(1) & " for " & strDateHeader
'Run the report
DoCmd.OpenReport strReportName, acViewPreview, , strWhere, , strReportHeader
DoCmd.Close acForm, strPromptForm
End Sub
Cheers
--
PeterK
Ofer Cohen said:
1. What is the point of the Me. prefix?
Me. Refer to the object (Form or Report) where the code is in.
Me.[TextBoxName] refer to the value of the text box within the current form.
You'll write
Forms![FormName].[FieldName]
if you want to refer to a text box in a form from a different object (form,
report, module, query)
******************************************
2. We have created the report from the values on the prompt form rather than
the report's query. Is that right? and is it the right way to do it?
If I understand the question, you mean that the report criteria is passing
using the WhereCondition of the OpenReport command line, rather then using
the query in the Report RecordSource.
If that the question, then Yes, it is the proper way of doing that for some
reasons.
* You can open the Report from different forms, if needed
* You can validate and change the criteria before openning the report, again
if needed
**********************************
3. It looks to me like OpenArgs can only ever feed one string to a report.
So for example you couldn't set the values for more than one text box in the
report header.
You can pass only one string, but you can pass few field values with a
seperator, and then split it in the report
Docmd.OpenReport "ReportName",,,,, Me.TExt1 & "-" & Me.Text2 & "-" & Me.Text3
Then, on the OnPrint event split the value by "-" (the seperator need to be
a value that won't apear in the text
Me.[TextBoxName1] = Split(Me.OpenArgs,"-")(0)
Me.[TextBoxName2] = Split(Me.OpenArgs,"-")(1)
Me.[TextBoxName3] = Split(Me.OpenArgs,"-")(2)
*********************************************
4. I printed my trial report and got the same data as in preview.
Note sure I understand the question.
Ofer