Problem with code on report

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

Guest

Table name is "Main"
Fields I am using to do the calc/query on: "Last_Name" and "Company_Room"
Report data source is Table.Main

To get a total count of rooms, I did: DCount(*) in text box and works fine.

Now I want to have a few fields that show how many rooms each company has
and how many of them are occupied. If I count the number of records where
Company_Room = "A", then I should get total number of rooms for Alpha Company.
If I want to see how many rooms are occupied by A then Company_Name = "A"
and Last_Name is not null would give it do me.

Can someone help me? I've tried everyway my limited knowledge will let me
and I can't get it to work.

Thanks!
 
You can use something like

=Sum(IIf([Room]="A" And [Last_name] Is Not Null, 1 , 0))

You can use the sum and iif with any criteria , and just sum 1 when the
criteria is true
 
I didn't even think of that approach! That's why your the MVP!

Thanks!

Ofer Cohen said:
You can use something like

=Sum(IIf([Room]="A" And [Last_name] Is Not Null, 1 , 0))

You can use the sum and iif with any criteria , and just sum 1 when the
criteria is true

--
Good Luck
BS"D


SFC Traver said:
Table name is "Main"
Fields I am using to do the calc/query on: "Last_Name" and "Company_Room"
Report data source is Table.Main

To get a total count of rooms, I did: DCount(*) in text box and works fine.

Now I want to have a few fields that show how many rooms each company has
and how many of them are occupied. If I count the number of records where
Company_Room = "A", then I should get total number of rooms for Alpha Company.
If I want to see how many rooms are occupied by A then Company_Name = "A"
and Last_Name is not null would give it do me.

Can someone help me? I've tried everyway my limited knowledge will let me
and I can't get it to work.

Thanks!
 
Not an MVP, but thanks for the thought,
I have a long way before I'll become one.

--
Good Luck
BS"D


SFC Traver said:
I didn't even think of that approach! That's why your the MVP!

Thanks!

Ofer Cohen said:
You can use something like

=Sum(IIf([Room]="A" And [Last_name] Is Not Null, 1 , 0))

You can use the sum and iif with any criteria , and just sum 1 when the
criteria is true

--
Good Luck
BS"D


SFC Traver said:
Table name is "Main"
Fields I am using to do the calc/query on: "Last_Name" and "Company_Room"
Report data source is Table.Main

To get a total count of rooms, I did: DCount(*) in text box and works fine.

Now I want to have a few fields that show how many rooms each company has
and how many of them are occupied. If I count the number of records where
Company_Room = "A", then I should get total number of rooms for Alpha Company.
If I want to see how many rooms are occupied by A then Company_Name = "A"
and Last_Name is not null would give it do me.

Can someone help me? I've tried everyway my limited knowledge will let me
and I can't get it to work.

Thanks!
 
Have a new problem. When I use the code, it works fine, but I get continuous
records showing on the report. I just want one single page that lists the 14
companies total rooms assigned, vacant, and occupied. How do I get it not to
display the records as it counts them?
Thanks!

Ofer Cohen said:
Not an MVP, but thanks for the thought,
I have a long way before I'll become one.

--
Good Luck
BS"D


SFC Traver said:
I didn't even think of that approach! That's why your the MVP!

Thanks!

Ofer Cohen said:
You can use something like

=Sum(IIf([Room]="A" And [Last_name] Is Not Null, 1 , 0))

You can use the sum and iif with any criteria , and just sum 1 when the
criteria is true

--
Good Luck
BS"D


:

Table name is "Main"
Fields I am using to do the calc/query on: "Last_Name" and "Company_Room"
Report data source is Table.Main

To get a total count of rooms, I did: DCount(*) in text box and works fine.

Now I want to have a few fields that show how many rooms each company has
and how many of them are occupied. If I count the number of records where
Company_Room = "A", then I should get total number of rooms for Alpha Company.
If I want to see how many rooms are occupied by A then Company_Name = "A"
and Last_Name is not null would give it do me.

Can someone help me? I've tried everyway my limited knowledge will let me
and I can't get it to work.

Thanks!
 
In that case you need to create a group by query, that counts the records and
returns one line for each company.

And then base the report on this query

--
Good Luck
BS"D


SFC Traver said:
Have a new problem. When I use the code, it works fine, but I get continuous
records showing on the report. I just want one single page that lists the 14
companies total rooms assigned, vacant, and occupied. How do I get it not to
display the records as it counts them?
Thanks!

Ofer Cohen said:
Not an MVP, but thanks for the thought,
I have a long way before I'll become one.

--
Good Luck
BS"D


SFC Traver said:
I didn't even think of that approach! That's why your the MVP!

Thanks!

:

You can use something like

=Sum(IIf([Room]="A" And [Last_name] Is Not Null, 1 , 0))

You can use the sum and iif with any criteria , and just sum 1 when the
criteria is true

--
Good Luck
BS"D


:

Table name is "Main"
Fields I am using to do the calc/query on: "Last_Name" and "Company_Room"
Report data source is Table.Main

To get a total count of rooms, I did: DCount(*) in text box and works fine.

Now I want to have a few fields that show how many rooms each company has
and how many of them are occupied. If I count the number of records where
Company_Room = "A", then I should get total number of rooms for Alpha Company.
If I want to see how many rooms are occupied by A then Company_Name = "A"
and Last_Name is not null would give it do me.

Can someone help me? I've tried everyway my limited knowledge will let me
and I can't get it to work.

Thanks!
 

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