Applying Filters

G

Guest

Hello again .. sorry about so many questions ...

I am attempting to apply a filter to a form. The Filter that I am
attempting to apply is:
[Station] = UID_Station ( <-- which is a string)
and
movement![Date] = [DATE]= Between #" & DateAdd("d", -1, Format(Now(),
"mm/dd/yyyy")) & "# and #" & DateAdd("d", 1, Format(Now(), "mm/dd/yyyy")) &
"#)"

I was trying to put them into a single filed strfilter (which Dimed as a
String)
then using this code

Me.Filter = strfilter
Me.FilterOn = True

Each filter works OK by itself ... but not together.

Can then be combined?

Thanks again

Jerry
 
G

Guest

Jerry,

When you build the strfilter string, make sure you have the word AND in
between the two halves:

strfilter= "[Station] ='" & UID_Station & "' AND [Date] ]= Between #" &
DateAdd ..."

HTH,

Ed
 
G

Guest

Hi Ed,

I did ... here is the code

strfilter = "([Station] ='" & UID_Station & "') and ([DATE]= Between #" &
DateAdd("d", -1, Format(Now(), "mm/dd/yyyy")) & "# and #" & DateAdd("d", 1,
Format(Now(), "mm/dd/yyyy")) & "#)"

Thanks

--
Jerry


Ed B said:
Jerry,

When you build the strfilter string, make sure you have the word AND in
between the two halves:

strfilter= "[Station] ='" & UID_Station & "' AND [Date] ]= Between #" &
DateAdd ..."

HTH,

Ed


Jerry Mc Cauley said:
Hello again .. sorry about so many questions ...

I am attempting to apply a filter to a form. The Filter that I am
attempting to apply is:
[Station] = UID_Station ( <-- which is a string)
and
movement![Date] = [DATE]= Between #" & DateAdd("d", -1, Format(Now(),
"mm/dd/yyyy")) & "# and #" & DateAdd("d", 1, Format(Now(), "mm/dd/yyyy")) &
"#)"

I was trying to put them into a single filed strfilter (which Dimed as a
String)
then using this code

Me.Filter = strfilter
Me.FilterOn = True

Each filter works OK by itself ... but not together.

Can then be combined?

Thanks again

Jerry
 
G

Guest

Hi Jerry,

Here's a sample how to filter with ADO: User can anter their criteria in a
form (I assumed you have a text box call: txtUID_Station, and a text box
txtDate) and click a command button for filter
Private Sub cmdSearch_Click()
Dim varWhere As Variant
' Initialize to Null
varWhere = Null

' If specified a station value
If Not IsNull(Me.txtUID_Station) Then
' .. build the predicate
varWhere = "[Station] LIKE '" & Me.txtUID_Station & "*'"
'OR varWhere = "[Station] ='" & Me.txtUID_Station * "'"
End If

' Do Date next
If Not IsNull(Me.txtDate) Then
' .. build the predicate
' Note: taking advantage of Null propogation
' so we don't have to test for any previous predicate
varWhere = (varWhere + " AND ") & "[DATE] = '" & Me.txtDate & "'"
'<--- Put you date calculation here)
End If
' Check to see that we built a filter
If IsNull(varWhere) Then
MsgBox "You must enter at least one search criteria.",
vbInformationMe.Caption
Exit Sub
End If

' See if any rows with a quick DLookup
If IsNull(DLookup("Station", "tblStation", varWhere)) Then
MsgBox "No Station meet your criteria.", vbInformation, Me.Caption
Exit Sub
End If

' Open Station filtered
' Note: if form already open, this just applies the filter
DoCmd.OpenForm "frmStation", WhereCondition:=varWhere '---> you can open
form, report, query...
' Done

I hope this help to solve your problem. If you need more help or with DAO
using querydef than let me know.

Good luck,
VP

Ed B said:
Jerry,

When you build the strfilter string, make sure you have the word AND in
between the two halves:

strfilter= "[Station] ='" & UID_Station & "' AND [Date] ]= Between #" &
DateAdd ..."

HTH,

Ed


Jerry Mc Cauley said:
Hello again .. sorry about so many questions ...

I am attempting to apply a filter to a form. The Filter that I am
attempting to apply is:
[Station] = UID_Station ( <-- which is a string)
and
movement![Date] = [DATE]= Between #" & DateAdd("d", -1, Format(Now(),
"mm/dd/yyyy")) & "# and #" & DateAdd("d", 1, Format(Now(), "mm/dd/yyyy")) &
"#)"

I was trying to put them into a single filed strfilter (which Dimed as a
String)
then using this code

Me.Filter = strfilter
Me.FilterOn = True

Each filter works OK by itself ... but not together.

Can then be combined?

Thanks again

Jerry
 
T

Tim Ferguson

and ([DATE]= Between

should read

AND (Date() BETWEEN DateOne AND DateTwo)

The keyword BETWEEN is the operator, there is no place for the equals
operator as well.

Hope that helps


Tim F
 

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