S
SteveC
Worked like a charm. I did have FirstName and LastName fields but it was
simple to just add a new field to Staff Table for FullName so I used that!
I will start fresh in the morning on the other nagging problem
I also found the answer to why I could not get rid of or change
relationships. It had to do with a hidden table called MSOBjs or something
or other; I gave myself permissions to break links and got rid of ComputerID
on the Accessories table since I tie accessories like computers to the
location. I then had to do something or other to AccessoriesSbf to get them
to show on the Locations Form. Apparently, I cannot allow edits on the
subforms if I want them to show up; not sure why. That is for another day.
I got it to work. Thanks.
simple to just add a new field to Staff Table for FullName so I used that!
I will start fresh in the morning on the other nagging problem
I also found the answer to why I could not get rid of or change
relationships. It had to do with a hidden table called MSOBjs or something
or other; I gave myself permissions to break links and got rid of ComputerID
on the Accessories table since I tie accessories like computers to the
location. I then had to do something or other to AccessoriesSbf to get them
to show on the Locations Form. Apparently, I cannot allow edits on the
subforms if I want them to show up; not sure why. That is for another day.
I got it to work. Thanks.
Graham Mandeno said:Hi Steve
The reason you need a combo box to show the staff member's name is that
the Staff table is not included in your query, so you need the RowSource
of the combo box to do the lookup and translate the StaffID value into a
displayable name. You can get around that by adding the Staff table to
your query. I don't know what your field names are, but it should look
something like this:
SELECT Computers.*, Staff.StaffName FROM
(Staff RIGHT JOIN Locations ON Staff.StaffID = Locations.StaffID)
RIGHT JOIN Computers ON Locations.LocationID = Computers.LocationID;
You can then bind StaffName to a textbox and make it disabled and locked
so users don't think they can change it.
Note that you need the RIGHT JOINs only if there are some computers that
don't have a LocationID. If this is not the case, then use INNER JOINs
instead.
--
Good Luck!
Graham Mandeno [Access MVP]
Auckland, New Zealand
SteveC said:Graham,
Perhaps this info will also help. The Control Source for my Computers
form is:
SELECT Computers.*, Locations.StaffID FROM Locations RIGHT JOIN Computers
ON Locations.LocationID=Computers.LocationID;
This is because when I choose a room to add computers to or to add
maintenance, it is tied to the location. Each location is assigned to a
person, so I have a field from Staff Table (StaffID). This field shows
when I select the location; I cannot change it, but for some reason, it
only shows correctly, if it is as a drop down list (though locked) (Note:
I would prefer just to have a simple text field as the drop down button
makes it look as though it is selectable. Another dilemma). Anyhow to
get the Staff ID to show requires I do a query and this query changes the
form's Control Source to what I have above. Could this be the reason,
the maintenance Cost doesn't show? I don't see why since it will do
correctly when there is an amount other than null for the Maintenance
Cost.
Thanks again for your patience.
Graham Mandeno said:Hi Steve
It's hard to see what you added below. The convention is to put inline
answers on new lines without the > prefix.
Nevertheless, I have trouble understanding why you would get "#Name?"
under some circumstances (no records) and not others. "#Error" I could
understand, but not "#Name?".
Are you *sure* that txtMaintenanceCount and the TotalMaintenanceCost
textbox on your main form both show the correct values if there is at
least one record in the subform?
You say that txtMaintenanceCount returns "#Name?". That implies its
ControlSource is referring to something whose name can't be resolved.
Can you confirm that its ControlSource is:
=[MaintenanceSbf].[Form].[Recordset].[RecordCount]
You never said which version of Access you are using. Is it prior to
Access 2000? If so, then a Form object does not have a Recordset
property, so you must use RecordsetClone instead:
=[MaintenanceSbf].[Form].[RecordsetClone].[RecordCount]
--
Graham Mandeno [Access MVP]
Auckland, New Zealand
Answers below, and thanks!
Hi Steve
Let's get a few things straight here. I understand that:
1. Your "Computers form" is a main form Yes
2. It contains a subform control named "MaintenanceSbf" Yes
3. This subform control has both LlinkMasterFields and LinkChildFields
set
to "ComputerID"Yes (
4. The subform contained in that control has a field named
"MaintenanceCost"
5. You have a textbox in the footer of that subform named "Total
Maintenance Cost" (BTW, I advise against using non-alphanumeric
characters, including spaces, in fieldnames or control names). I
changed it to TotalMaintenanceCost
6. The control source of this textbox is:
=Nz(Sum([MaintenanceCost]), 0)
7. On the main form you have a textbox whose control source is:
=[MaintenanceSbf].[Form]![Total Maintenance Cost]
Please tell me if ANY of the premises above is incorrect.
Now some questions: What do you see in (a) the total textbox on the
subform and (b) the total textbox on the main form in each of the
following cases:
1. The current computer has one or more maintenance records with a
non-null value for MaintenanceCost?
2. The current computer has one or more maintenance records, but they
all
have a null value for MaintenanceCost?
3. The current computer does not have any related maintenance records?
Am I correct that the problem occurs only in the third case? Yes
If so, then add another textbox to your main form named
"txtMaintenanceCount". Set its control source to the following:
=[MaintenanceSbf].[Form].[Recordset].[RecordCount]
Now, change the controlsource of the textbox in (7) above to:
=IIf([txtMaintenanceCount]=0, 0, [MaintenanceSbf].[Form]![Total
Maintenance Cost])
Try it and report back. It didn't work. The txtMaintenanceCount
returns Name? and the box (7 above) is also Name?
Don't feel that you're wasting anybody's time. We do this because we
like
to help. I would only consider I had wasted my time if you gave up
before
reaching a solution
--
Good Luck!
Graham Mandeno [Access MVP]
Auckland, New Zealand
OK, Graham, I have wasted enough of your time, and you have my
deepest
appreciation. What you wrote worked like a charm on my Locations
Form
for
accessories and computers cost. However, it does not seem to work on
my
Computers Form with Maintenance Subform.
Current Configuration: It works if totals are not null
On MaintenanceSbf, I have a field that is labeled Total Maintenance
Cost
and
the Control Source is =Sum[MaintenanceCost])
On Computers form, I have a field that is labeled Total Maintenance
and
the
Control Source is
=IIf(IsNull([ComputerID]),0,DSum("[MaintenanceCost]","Maintenance","[ComputerID]="
& [ComputerID]))
I tried to change it to:
On MaintenanceSbf, Total Maintenance Cost and the Control Source is
=Nz(Sum([MaintenanceCost]), 0)
On Computers form, I have a field that is labeled Total Maintenance
and
the
Control Source is
[MaintenanceSbf].Form![Total Maintenance Cost]
This begets #Name?
I think the problem may be something to do with ComputerID stuff.
Thanks
again, and I promise this is my last post.
Hi Steve
The idea of using a textbox to count the records in the subform is
simply so you can get around the problem of "#Error!" when there are
no
records to sum. You don't need to *display* the txtCount textbox if
you
don't want to - just set its Visible property to False.
If there are records in your subform, but all of them have Null in
the
Maintenance field, then =Sum([Maintenance]) will return Null also.
Then, if you try to add Null to a number, that also will return
Null.
The trick is to use the Nz function to convert the Null to zero, and
then you can add it. So change the SumMaintenance control source to:
=Nz(Sum([Maintenance]), 0)
As John explained, there is a difference between DataEntry and
AllowAdditions. DataEntry suppresses the display of existing
records,
allowing you only to add new ones. If DataEntry is False and
AllowAdditions is True, then you can view/edit existing records
*and*
add new ones.
--
Good Luck!
Graham Mandeno [Access MVP]
Auckland, New Zealand