Syntax to refer to subform in BuildCriteria statement - Access 2k

  • Thread starter Leonard Priestley
  • Start date
L

Leonard Priestley

I have designed a form for previewing reports. It has a combo box for
selecting the report, a combo box for selecting the person whose data I
want, and two text boxes to enable me to specify the start and end dates for
the data.

I am writing code to construct a strWhereClause to use with
'DoCmd.OpenReport'. My intention is to use the BuildCriteria Method to
construct a clause that specifies the person, and the Start and End dates.
When I open my report form directly and use it with the code below it works
fine.

strWhereClause = "(" & BuildCriteria("PersonID", dbLong,
frmReport.cboStaffMember) & ")"
strWhereClause = strWhereClause & " AND " & "(" & BuildCriteria("Date",
dbDate, ">= frmReport.txtStartDate") & ")"
strWhereClause = strWhereClause & " AND " & "(" & BuildCriteria("Date",
dbDate, "=< frmReport.txtEndDate") & ")"

However, the next step (which is giving me problems) is that I want to use a
main form to host several forms, including the report form. They are all
treated as source objects for a subform (which I have called
IntroPanel_child) on the main form . This means I have to extend the syntax
when I access the report form from the main form.

So far I have this:

strWhereClause = "(" & BuildCriteria)"PersonID", dbLong,
Forms![frmMain]![IntroPanel_child]. _
frmReport.cboStaffMember) & ")"
strWhereClause = strWhereClause & " AND " & "(" & BuildCriteria("Date",
dbDate, ">= Forms! _
[frmMain]![IntroPanel_child].frmReport.txtStartDate") & ")"
strWhereClause = strWhereClause & " AND " & "(" & BuildCriteria("Date",
dbDate, "=<Forms! _
[frmMain]![IntroPanel_child].frmReport.txtEndDate") & ")"

Whether I access the report form directly, or via the main form, I get boxes
requesting I enter a parameter value. If I try to do this for the dates, I
get a message saying "Expression typed incorrectly, or is too complex to be
evaluated". These Messages only appear after I press the 'preview' command
button.

If I comment out the statements relating to date, and retain only the first
part, specifying the staff member, the code works OK.

I would appreciate some help on this. It's drivng me nuts.

Leonard Priestley
 
L

Leonard Priestley

Please don't bother about this anyone. It's great what a good night's sleep
can do - I got it sussed.
In case anyone is interested, I made the mistake of referring to both the
subform, and the form I was using as a source object. I needed to retain
IntroPanel_child, but drop frmReport from the string. If anyone put work
into trying to find a solution for me I apologise for wasting your time.

Leonard Priestley
 

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