number of record from query and two combo boxes (1 Viewer)

ryprobg

Member
Local time
Today, 07:44
Joined
Sep 3, 2022
Messages
59
i have a form named (TR Jours par Service) with two combobox (sc_cbo) for select services and (day_cbo) for select days of month and a query (Q_JM_select_TM) loaded from a table (t_rec).
i try to get number of records of one service in day (day_cbo) where i select sc_cbo and day_cbo
i try for many ways but no success
code : dcount("id_dec";"t_rec";"[sc_main] = Forms![TR jours par Service]![sc_cbo]")
please look to the picture below to know more
 

Attachments

  • dcount problm.jpg
    dcount problm.jpg
    3.5 MB · Views: 73

Ranman256

Well-known member
Local time
Today, 02:44
Joined
Apr 9, 2015
Messages
4,337
what about:
if [sc_main] is numeric:
dcount("*","t_rec","[sc_main] =" & Forms![TR jours par Service]![sc_cbo])

or

if [sc_main] is text:
dcount("*","t_rec","[sc_main] ='" & Forms![TR jours par Service]![sc_cbo] & "'")

the form path is outside the quotes.
 

ryprobg

Member
Local time
Today, 07:44
Joined
Sep 3, 2022
Messages
59
what about:
if [sc_main] is numeric:
dcount("*","t_rec","[sc_main] =" & Forms![TR jours par Service]![sc_cbo])

or

if [sc_main] is text:
dcount("*","t_rec","[sc_main] ='" & Forms![TR jours par Service]![sc_cbo] & "'")

the form path is outside the quotes.
thank you for your anser;
the problem here is i want to get number of records (sc_main) in one day whene i select the combobox of days (day_cbo) in the selected date ,
you should know that day_cbo is a numeric field
 

ryprobg

Member
Local time
Today, 07:44
Joined
Sep 3, 2022
Messages
59
i have a form named (TR Jours par Service) with two combobox (sc_cbo) for select services and (day_cbo) for select days of month and a query (Q_JM_select_TM) loaded from a table (t_rec).
i try to get number of records of one service in selected day (day_cbo) when i select sc_cbo and day_cbo
i try for many ways but no success
code : dcount("id_dec","t_rec","[sc_main] = Forms![TR jours par Service]![sc_cbo]")
please look to the picture below to know more
how i can add day_cbo in the code to get number of records?
 

Attachments

  • dcount problm.jpg
    dcount problm.jpg
    3.5 MB · Views: 71

Pat Hartman

Super Moderator
Staff member
Local time
Today, 02:44
Joined
Feb 19, 2002
Messages
43,275
If you switch the query to SQL view, I think you'll get an English version of the query. It won't change your table and column names but it will change the VBA and SQL function names and arguments. That might get more help for you.
 

ryprobg

Member
Local time
Today, 07:44
Joined
Sep 3, 2022
Messages
59
If you switch the query to SQL view, I think you'll get an English version of the query. It won't change your table and column names but it will change the VBA and SQL function names and arguments. That might get more help for you.
SELECT t_rec.nature, t_rec.sc_main, Format(Val(Day([deb])),"00") AS [jours rec], DCount("*","t_rec","[sc_main] ='" & [Forms]![TR jours par Service]![sc_cbo] & "'") AS NR, Month([deb]) AS Expr1, Format(Val(Month([deb])),"00") AS Expr1, Sum(DateDiff('h',[deb],[fin])) AS TR
FROM t_rec
GROUP BY t_rec.nature, t_rec.sc_main, Format(Val(Day([deb])),"00"), Month([deb]), Format(Val(Month([deb])),"00")
HAVING (((t_rec.sc_main)=[Formulaires]![TR jours par Service]![sc_cbo]) AND ((Format(Val(Day([deb])),"00"))=[Formulaires]![TR jours par Service]![day_cbo]) AND ((Month([deb]))=Month(Now())));
 

ryprobg

Member
Local time
Today, 07:44
Joined
Sep 3, 2022
Messages
59
If you switch the query to SQL view, I think you'll get an English version of the query. It won't change your table and column names but it will change the VBA and SQL function names and arguments. That might get more help for you.
i can simple all of this :
how i can get number of (sc_main) recodrs with select (sc_cbo) and today date
how i cant get it..i mean two createria in dcount function
 

Gasman

Enthusiastic Amateur
Local time
Today, 07:44
Joined
Sep 21, 2011
Messages
14,299
i have a form named (TR Jours par Service) with two combobox (sc_cbo) for select services and (day_cbo) for select days of month and a query (Q_JM_select_TM) loaded from a table (t_rec).
i try to get number of records of one service in selected day (day_cbo) when i select sc_cbo and day_cbo
i try for many ways but no success
code : dcount("id_dec","t_rec","[sc_main] = Forms![TR jours par Service]![sc_cbo]")
please look to the picture below to know more
how i can add day_cbo in the code to get number of records?
Adding one extra sentence to your original post is not going to help your situation much. :(
What is wrong with continuing the criteria with And and the rest of the criteria?
I would put the criteria into a string variable and debug.print until correct, then use that variable in the function.
Plus you can copy and paste that back here if you cannot get it right, with the function?
 

ryprobg

Member
Local time
Today, 07:44
Joined
Sep 3, 2022
Messages
59
Adding one extra sentence to your original post is not going to help your situation much. :(
What is wrong with continuing the criteria with And and the rest of the criteria?
I would put the criteria into a string variable and debug.print until correct, then use that variable in the function.
Plus you can copy and paste that back here if you cannot get it right, with the function?
NR: dcount("*","t_rec","[sc_main] = '[Forms]![TR jours par Service]![sc_cbo]" and "[deb]>=date()'")
but the problem the result is the total number of records not number of records of today
[deb] is my date field
 

ryprobg

Member
Local time
Today, 07:44
Joined
Sep 3, 2022
Messages
59
NR: dcount("*","t_rec","[sc_main] = '[Forms]![TR jours par Service]![sc_cbo]" and "[deb]>=date()'")
but the problem the result is the total number of records not number of records of today
[deb] is my date field
can you help me Gasman :)
 

Gasman

Enthusiastic Amateur
Local time
Today, 07:44
Joined
Sep 21, 2011
Messages
14,299
Put it all into that variable and debug.print it.
Your quotes are all in the wrong places. You need to concatenate control values or variables into the criteria, so it would look like
Scmain=12 and deb >= #09/17/2022#
 

Users who are viewing this thread

Top Bottom