Count records

J

jefferysf

Hi - I am building a database to manage corporate jets. My form has flight
information and a field for "Number of Passengers". There is a subform for
each form that has a row for each passenger with passenger information. How
can I get the form to populate the "Number o Passengers" field by counting
the rows in the subform? Any help will be greatly appreciated!! Thanks.
 
M

Michel Walsh

DCount("*", "tableNameHere",
"FlightNumber=FORMS!FormNameHere!ControlWIthFligthNumberHere")


should return the number of records for the given flight number,


DCount("PassengerID", "tableNameHere",
"FlightNumber=FORMS!FormNameHere!ControlWIthFligthNumberHere")


returns the number of records where there is a passengerID value, for the
given flight number.



Hoping it may help,
Vanderghast, Access MVP
 
J

jefferysf

Thanks Michael...

I right clicked in Design View on the Number of Passengers field and selected
Build Event then Expression Builder and entered

=DCount("PassengerID","tblTripPassengers","TripDetailID=FORMS!
frmTripPassengers!ControlWithTripDetailID") but it is still not returning a
number. Any ideas?


Michel said:
DCount("*", "tableNameHere",
"FlightNumber=FORMS!FormNameHere!ControlWIthFligthNumberHere")

should return the number of records for the given flight number,

DCount("PassengerID", "tableNameHere",
"FlightNumber=FORMS!FormNameHere!ControlWIthFligthNumberHere")

returns the number of records where there is a passengerID value, for the
given flight number.

Hoping it may help,
Vanderghast, Access MVP
Hi - I am building a database to manage corporate jets. My form has
flight
[quoted text clipped - 4 lines]
can I get the form to populate the "Number o Passengers" field by counting
the rows in the subform? Any help will be greatly appreciated!! Thanks.
 
G

Guest

Hi Jeffery,

Try appending the value of your data like this:

=DCount("PassengerID","tblTripPassengers","TripDetailID=" &
me.ControlWithTripDetailID)

Naturally you need to replace the "ControlWithTripDetailID" with the actual
name of the control on your form that has that ID in it.

Damian.

jefferysf said:
Thanks Michael...

I right clicked in Design View on the Number of Passengers field and selected
Build Event then Expression Builder and entered

=DCount("PassengerID","tblTripPassengers","TripDetailID=FORMS!
frmTripPassengers!ControlWithTripDetailID") but it is still not returning a
number. Any ideas?


Michel said:
DCount("*", "tableNameHere",
"FlightNumber=FORMS!FormNameHere!ControlWIthFligthNumberHere")

should return the number of records for the given flight number,

DCount("PassengerID", "tableNameHere",
"FlightNumber=FORMS!FormNameHere!ControlWIthFligthNumberHere")

returns the number of records where there is a passengerID value, for the
given flight number.

Hoping it may help,
Vanderghast, Access MVP
Hi - I am building a database to manage corporate jets. My form has
flight
[quoted text clipped - 4 lines]
can I get the form to populate the "Number o Passengers" field by counting
the rows in the subform? Any help will be greatly appreciated!! Thanks.
 
J

jefferysf

Thanks Damian -

what is the [me] in your expression? When you say the actual name of the
control do I want to insert PasengerID, leave TripDetailID (which is the
flight number) or am I completely missing something?

Damian said:
Hi Jeffery,

Try appending the value of your data like this:

=DCount("PassengerID","tblTripPassengers","TripDetailID=" &
me.ControlWithTripDetailID)

Naturally you need to replace the "ControlWithTripDetailID" with the actual
name of the control on your form that has that ID in it.

Damian.
Thanks Michael...
[quoted text clipped - 24 lines]
 
G

Guest

Hi Jeff,

Me is a reference to the current object, ie: your form. I was assuming you
had this control on a form (since the post is in the Forms forum).

On your form somewhere you must have a TripDetailID or some other field that
holds that information. This is the field that you want to reference. If
the TripDetailID = the Flight Number, you use me.[Flight Number] or whatever
your Flight Number text box is called.

Damian.

Damian.

jefferysf said:
Thanks Damian -

what is the [me] in your expression? When you say the actual name of the
control do I want to insert PasengerID, leave TripDetailID (which is the
flight number) or am I completely missing something?

Damian said:
Hi Jeffery,

Try appending the value of your data like this:

=DCount("PassengerID","tblTripPassengers","TripDetailID=" &
me.ControlWithTripDetailID)

Naturally you need to replace the "ControlWithTripDetailID" with the actual
name of the control on your form that has that ID in it.

Damian.
Thanks Michael...
[quoted text clipped - 24 lines]
can I get the form to populate the "Number o Passengers" field by counting
the rows in the subform? Any help will be greatly appreciated!! Thanks.
 
J

jefferysf via AccessMonster.com

Damian said:
Hi Jeff,

Me is a reference to the current object, ie: your form. I was assuming you
had this control on a form (since the post is in the Forms forum).

On your form somewhere you must have a TripDetailID or some other field that
holds that information. This is the field that you want to reference. If
the TripDetailID = the Flight Number, you use me.[Flight Number] or whatever
your Flight Number text box is called.

Damian.

Damian.
Thanks Damian -
[quoted text clipped - 19 lines]
Thank you so much!!!!!!!
J
 

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