This seems like it should be a relatively straightforward task but I've tackled it a few different ways with no luck so far.
I have two tables : People and Addresses. I have a form with a recordsource that is a query joining these two tables. What I want to do is have the header display "The database currently contains [txtPersonCount] people at [txtAddressCount] addresses."
Since person key and address key are distinct within their respective tables my first thought was simply to set the controlsource of the textboxes to =Count([tblPeople].[PersonID])
and =Count([tblAddress].[AddressID])
.
Oddly, the count of address ID appears in both textboxes with this method. I assume what's happening is rather than counting the IDs from the respective tables, the IDs are being counted from the query behind the form's recordsource (for which there are more addresses than people, so it would make sense).
I then attempted to basically do the same thing by declaring my SQL queries as a string :
Dim sql As String
sql = "SELECT COUNT(tblPeople.[PersonID]) FROM tblPeople;"
Forms![frmBrowse].[txtPersonCount].ControlSource = sql
But that only ends up making the textbox display the text of the query. Changing the string to be "=SELECT COUNT...."
makes no difference.
Any ideas on how to solve this?