Count of records in Subforms

Misty

Registered User.
Local time
Today, 15:30
Joined
Nov 12, 2003
Messages
45
;)
In the attached dB, in the Log Entries form, I'm trying to get the passengers and crew counts on the left side of the form to be the total of the entries of the related Subforms on the right side of the form. Can someone help me with this?

P.S. The counts that are there now are user entered. I need them to be put in automaticly.

Thanks,
M
 

Attachments

Try this...

First, delete the control source of the PassengerCount textbox and name the textbox CountPassengers. Do the same with the CrewCount textbox and name it CountCrew. Just setting up new names for the text boxes that are not table field names.

Put this code in the main form's On Current event:

Code:
If IsNull(LogEntryNumber) = False Then
     Me.CountPassengers = DCount("LastName", "Passengers", "LogEntryNumber = " & Me.LogEntryNumber)
     Me.CountCrew = DCount("Last Name", "Crew Members", "LogEntryNumber = " & Me.LogEntryNumber)
End If

That should work. Hope that helps.
 
Hi Rich,
I did what you said and when I open the [Log Entries] form, I get an error: Runtime error '3075'. Syntax error (missing operator) in query expression 'Count(LastName)'.

When I click the debug button on the popup, it highlights this line of the code:

Me.CountCrew = DCount("Last Name", "Crew Members", "LogEntryNumber = " & Me.LogEntryNumber)


I've never even used DCount, so this is a learning experience for me all the way around.

Thanks for your help,
M ;)




RichO said:
Try this...

First, delete the control source of the PassengerCount textbox and name the textbox CountPassengers. Do the same with the CrewCount textbox and name it CountCrew. Just setting up new names for the text boxes that are not table field names.

Put this code in the main form's On Current event:

Code:
If IsNull(LogEntryNumber) = False Then
     Me.CountPassengers = DCount("LastName", "Passengers", "LogEntryNumber = " & Me.LogEntryNumber)
     Me.CountCrew = DCount("Last Name", "Crew Members", "LogEntryNumber = " & Me.LogEntryNumber)
End If

That should work. Hope that helps.
 
Hi again Rich

I figured out the error. In the "Passenger" line of code you had "LastName" and in the Crew line of code you had "Last Name". I took the space out of the Crew line and it worked perfectly!

Thank you, Thank you, Thank you! My boss will be very happy with me when I get this finished for him and this is "Raise Month".

M :p
 
Oops, my mistake, typo...

In the code line for CountCrew, "Last Name" should not have a space...

Me.CountCrew = DCount("LastName", "Crew Members",...

Try that out.
 

Users who are viewing this thread

Back
Top Bottom