Filter a form by the value of a control

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

Guest

Hello,

I have a from that I want to filter by the valu eof a text box but the
form keeps prompting me for the text box value upon loading... Here is the
SQL

SELECT tblSpeedOfService.SOSID, tblSpeedOfService.SOSDate,
tblSpeedOfService.DayPartID, tblSpeedOfService.SOSTime, Month([SOSDate]) AS
CurMonth, Year([SOSDate]) AS CurYear FROM tblSpeedOfService WHERE
(((tblSpeedOfService.DayPartID)=1) And
((Month([SOSDate]))=Forms!sfrmBreakfast!txtMonth) And
((Year([SOSDate]))=Forms!sfrmBreakfast!txtYear));
 
Really what I am looking to do is filter this form by Month and Year of a
date stored in tblSpeedofService.SOSDate
 
Really what I am looking to do is filter this form by Month and
Year of a date stored in tblSpeedofService.SOSDate

Take the filter out of the query, then pass it to the form as part
of the DoCmd.openform statement that opens your form

If you used the wizard to create the button that opens the form,
stWhereclause is defined but not populated.

You would define it as:
stWhereClause = " tblSpeedOfService.DayPartID= 1 And " & _
"Month([SOSDate]) = " & Me!txtMonth & " And " & _
"Year([SOSDate]) = " & Me!txtYear

Ernst Guckel said:
Hello,

I have a from that I want to filter by the valu eof a text box
but the
form keeps prompting me for the text box value upon loading...
Here is the SQL

SELECT tblSpeedOfService.SOSID, tblSpeedOfService.SOSDate,
tblSpeedOfService.DayPartID, tblSpeedOfService.SOSTime,
Month([SOSDate]) AS CurMonth, Year([SOSDate]) AS CurYear FROM
tblSpeedOfService WHERE (((tblSpeedOfService.DayPartID)=1) And
((Month([SOSDate]))=Forms!sfrmBreakfast!txtMonth) And
((Year([SOSDate]))=Forms!sfrmBreakfast!txtYear));
 
Actually what I did was to just change the recordsource in code to update the
SQL... works great... thanks for the reply...

Bob Quintal said:
Really what I am looking to do is filter this form by Month and
Year of a date stored in tblSpeedofService.SOSDate

Take the filter out of the query, then pass it to the form as part
of the DoCmd.openform statement that opens your form

If you used the wizard to create the button that opens the form,
stWhereclause is defined but not populated.

You would define it as:
stWhereClause = " tblSpeedOfService.DayPartID= 1 And " & _
"Month([SOSDate]) = " & Me!txtMonth & " And " & _
"Year([SOSDate]) = " & Me!txtYear

Ernst Guckel said:
Hello,

I have a from that I want to filter by the valu eof a text box
but the
form keeps prompting me for the text box value upon loading...
Here is the SQL

SELECT tblSpeedOfService.SOSID, tblSpeedOfService.SOSDate,
tblSpeedOfService.DayPartID, tblSpeedOfService.SOSTime,
Month([SOSDate]) AS CurMonth, Year([SOSDate]) AS CurYear FROM
tblSpeedOfService WHERE (((tblSpeedOfService.DayPartID)=1) And
((Month([SOSDate]))=Forms!sfrmBreakfast!txtMonth) And
((Year([SOSDate]))=Forms!sfrmBreakfast!txtYear));
 
Back
Top