referencing controls for report criteria

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am in the process of creating a database in which one of the forms has a
combo box, "cboProjectID", as part of a mainform, "frmSample". On the many
end of a one-to-many relationship is the field "SampleID" within a subform,
"frmSampleSubform". I am also placing either on the mainform or subform, a
form with an option group (radio buttons) so that users can print various
reports while in frmSample.

I'd like to avoid users having to enter the criteria in the form with the
option group, but rather have it reference what record is selected in
cboProjectID of the mainform and the SampleID field of the subform. How do I
go about doing this?...AND...Does it matter whether the option group is
located in the mainform or subform?

Thanks in advance for any suggestions/feedback!
 
Hi Kevin,

you can use the WHERE paparmeter of the OpenReport action to
limit your records

'~~~~~~~~~~
'save record
if me.dirty then me.dirty = false

if me.newrecord then
msgbox "you are not on a current record"
exit sub
end if

dim mWhere as string

mWhere = "ProjectID=" & me.cboProjectID

if me.frmSampleSubform.form.dirty then
me.frmSampleSubform.form.dirty = false

if not me.frmSampleSubform.form.newrecord then
mwhere = mWhere & " AND SampleID=" _
& me.frmSampleSubform.form.SampleID_controlname
end if

docmd.openreport "ReportName", _
, acPreview, , mWhere
'~~~~~~~~~~~~~~~~~~~

this code is written to go behind the main form, but it
could be changed to go behind the subform...

this is assuming that ProjectID and SampleId are both in the
recordset for your report


Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
Back
Top