how to refresh query when date of text box changed?

siamandm
BronzeLounger
Posts: 1227
Joined: 01 May 2016, 09:58

how to refresh query when date of text box changed?

Post by siamandm »

Hello All,
I have simple database, table with a query and form

I have two issues,
1- when I open the form frmSummary a little windows pop up to inter the date, how to stop this?
2- how to filter the sub form frmSummary when the date of the visitdate text box changes?

Regards
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78488
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: how to refresh query when date of text box changed?

Post by HansV »

The name of the field is Visit Date, not Visit_Date, so the SQL of qry01 should be

SELECT Count(*) AS total_visitors, Sum(IIf(gender='Male',1,0)) AS male_visitors, Sum(IIf(gender='Female',1,0)) AS female_visitors
FROM visitors
WHERE (((Visit Date])=[Forms]![frmSummary]![visitDate]));

The form will then be filtered when you enter a date in the text box.
Best wishes,
Hans

siamandm
BronzeLounger
Posts: 1227
Joined: 01 May 2016, 09:58

Re: how to refresh query when date of text box changed?

Post by siamandm »

thank you very much for the support,
when I change the date in the text box, I have to click outside then it will refresh the form, can we do something by just changing the date it refresh the form?

User avatar
HansV
Administrator
Posts: 78488
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: how to refresh query when date of text box changed?

Post by HansV »

No. You'd have to use the On Change event of the text box, but that would lead to problems since the text of the text box is usually not a valid date while you are entering/editing it.
Best wishes,
Hans

siamandm
BronzeLounger
Posts: 1227
Joined: 01 May 2016, 09:58

Re: how to refresh query when date of text box changed?

Post by siamandm »

thank you very much, so I think it is better to insert a button and add on click event to refresh the query.

User avatar
HansV
Administrator
Posts: 78488
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: how to refresh query when date of text box changed?

Post by HansV »

That's fine.
Best wishes,
Hans

siamandm
BronzeLounger
Posts: 1227
Joined: 01 May 2016, 09:58

Re: how to refresh query when date of text box changed?

Post by siamandm »

another question related to this please,

if there is a little table for Gender, with two row 1 for male and 2 for male ( the reason of using this is langue support for sql )

using this code is not counting !
male_visitors: Sum(IIf([gender]='1',1,0))
female_visitors: Sum(IIf(gender='2',1,0))
any solutions

User avatar
HansV
Administrator
Posts: 78488
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: how to refresh query when date of text box changed?

Post by HansV »

Is the Gender field a number field? If so, you should not use quotes around the values:

male_visitors: Sum(IIf([gender]=1,1,0))
female_visitors: Sum(IIf(gender=2,1,0))
Best wishes,
Hans

siamandm
BronzeLounger
Posts: 1227
Joined: 01 May 2016, 09:58

Re: how to refresh query when date of text box changed?

Post by siamandm »

Thank you very much i will give it a try