Problem with filtering subform

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

Guest

Well I was getting overconfident and thought I could get this to work.

I have a Combobox on the mainform 'Combo2'. The user is meant to type a
date into this feild.

The subform is a datasheet form with a feild called [date]. I attempted to
use the following code to filter the resultes of the subform and, needdless
to say, it failed. Anyhelp is greatly appreciated.

Private Sub Combo2_AfterUpdate()
Me!frm_timetrack.Form.Filter = "Me!frm_timetrack.Form!Date=#" & Me!Combo2 &
"#"
Me!frm_timetrack.Form.FilterOn = True
End Sub
 
Try this
On the After update event of the combo
Private Sub Combo2_AfterUpdate()
Me!frm_timetrack.Requery
End Sub

Chenge the record source of the subform, to lnk to the main form

Select * From TableName Where [DateFieldName] = Me!Combo2
============================================
Or link the main form and the sub form, using the child parent properties in
the subform
 
In the Filter String, you just use the Field name in the SubForm's
RecordSource rather than the full reference.

Try:

Me!frm_timetrack.Form.Filter = "[Date]=#" & Me!Combo2 & "#"

Note that this works only if:
* "frm_timetrack" in the name of the SubformCONTROL. Depending on your
set-up, the name of the SubformControl may be different from the name of the
Form being used as the "Subform" (more technically accurate, being used as
the SourceObject of the SubformControl).
* Your Regional date format is "mm/dd/yyyy". If your Regional date format
is different, you need to reformat it to the US format "mm/dd/yyyy" and
enclosed in hashes (#).

BTW, "Date" is a bad Field name as "Date" is also a reserved word for the
Date() function. If it is still possible, suggest you change the Field name
to something else. Otherwise, make sure you enclosed "Date" in square
brackets if you want to refer to the Field and not the function Date() which
is accepted in VBA WITHOUT parentheses.
 

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

Back
Top