MS Access Forum / General 2 / October 2007
Budget Subforms
|
|
Thread rating:  |
meghanwh@gmail.com - 13 Oct 2007 16:13 GMT I have a project for a client that is essentially goals and subgoals, so for instance, you have goal 1 and subgoal 1.1. I've created a table tblBudget with fields BudgetLineID, BudgetGoalNumber, Amount and BudgetCategory (which comes from a separate categories table). I created a form with a subform to enter the different budget amounts, it opens from the form which you enter the goals and takes the goal number as a filter for the budget form. The client would like the budget to display the sum of all the subgoals, as well as have the opportunity to enter ine items for that goal.
So for instance, if I open the budget form for goal 1, it has the subform which I've already created which shows you the line items for goal 1, and then has another box which has a sum of goals 1.1, 1.2, 1.1.1, etc.
Any hope? Thanks!
Ken Snell (MVP) - 13 Oct 2007 16:22 GMT Put a textbox in the subform's Form Footer section. Set its Control Source to =Sum([NameOfFieldThatYouWantToSum])
 Signature Ken Snell <MS ACCESS MVP>
>I have a project for a client that is essentially goals and subgoals, > so for instance, you have goal 1 and subgoal 1.1. I've created a table [quoted text clipped - 12 lines] > > Any hope? Thanks! meghanwh@gmail.com - 13 Oct 2007 16:58 GMT On Oct 13, 11:22 am, "Ken Snell \(MVP\)" <kthsneisll...@ncoomcastt.renaetl> wrote:
> Put a textbox in the subform's Form Footer section. Set its Control Source > to [quoted text clipped - 27 lines] > > - Show quoted text - I do have a box on the subform that sums up the totals on the subform, but the part i'm having trouble with is getting the other subgoals. For instance, the subform has line items for goal 1.1, and I need to have the total of goals 1.1.1, 1.1.2, 1.1.1.1, etc., and those goals are not on the subform. It's essentially the sum of goal 1.1*, I just don't knwo how to code that. Thanks.
Ken Snell (MVP) - 13 Oct 2007 17:25 GMT Let's start with a clear picture of your form and subform design -- include the SQL statements for the form's and subform's RecordSources. Tell us about the actual data -- field names, table names, examples of data values.
If you're not including the "subsubgoal" data in the subform, then how are those data associated to the subgoal data?
 Signature
Ken Snell <MS ACCESS MVP>
> On Oct 13, 11:22 am, "Ken Snell \(MVP\)" > <kthsneisll...@ncoomcastt.renaetl> wrote: [quoted text clipped - 37 lines] > are not on the subform. It's essentially the sum of goal 1.1*, I just > don't knwo how to code that. Thanks. meghanwh@gmail.com - 15 Oct 2007 01:45 GMT On Oct 13, 12:25 pm, "Ken Snell \(MVP\)" <kthsneisll...@ncoomcastt.renaetl> wrote:
> Let's start with a clear picture of your form and subform design -- include > the SQL statements for the form's and subform's RecordSources. Tell us about [quoted text clipped - 52 lines] > > are not on the subform. It's essentially the sum of goal 1.1*, I just > > don't knwo how to code that. Thanks. Form: frmBudgetForm. RecordSource: qryBudget SELECT [GoalNumber], [GoalBudget]
>From [tblMainGoals] UNION SELECT [Level2Number], [Level2Budget] FROM [tblLevel2Goals]; UNION SELECT [Level3Number], [Level3Budget] FROM [tblLevel3Goals] UNION SELECT [Level4Number], [Level4Budget] FROM [tblLevel4Goals] UNION SELECT [Level5Number], [Level5Budget] FROM [tblLevel5Goals] UNION SELECT [Level6Number], [Level6Budget] FROM [tblLevel6Goals];
Subform was created within the form, called qryBudget subform RecordSouce: SELECT tblBudget.BudgetLineID, tblBudget.BudgetGoalNumber, tblBudget.Amount, tblBudget.BudgetCategory FROM tblBudget;
On frmBudgetForm the only field is a text box TotalBudget=[qryBudget subform].Form!TotalAmount On qryBudget subform the fields are BudgetLineID (text box), BudgetGoalNumber (Text box), Amount (text box) and Combo8 which is the Budget categories: SELECT tblBudgetCategories.BudgetCategoryID, tblBudgetCategories.BudgetCategory FROM tblBudgetCategories; In the form footer I have a hidden control text box TotalAmount=Sum([Amount])
Sample data might be: ID: 1 Goal Number: 1 Amount: $100.00 Category: Travel
ID: 2 Goal Number: 1.1 Amount: $50.00 Category: Office Supplies
ID: 3 Goal Number: 1.1 Amount $25.00 Category: Travel
ID: 4 Goal Number: 1.1.1 Amount: $50.00 Category: Misc
The goals go down 6 levels to 1.2.3.4.5.6, and I need to know a total amount of all the subgoals for any particular goal. So for instance, if I open the form to goal 1.1, I need to have it add the specific line items that apply to 1.1, but also the line items that apply to 1.1.2, 1.1.2.3, etc., essentially to GoalNumber*.
Should I change the record source of frmBudgetForm to tblBudget? I think one of the problems I have is I don't know how to relate the subsubform data to the subform or to the actual form. It doesn't seem like a direct relationship to me, and it seems like one that would have to be created artificially.
Thanks so much.
Ken Snell (MVP) - 15 Oct 2007 18:41 GMT If I'm understanding your setup correctly, I think you can get your desired result if you put another textbox in the Detail section of the subform (name the textbox txtSubGoalTotal), and set its RecordSource to this expression:
=DSum("Amount", "tblBudget", "[BudgetGoalNumber] Like " & [BudgetGoalNumber] & "*")
 Signature Ken Snell <MS ACCESS MVP>
> On Oct 13, 12:25 pm, "Ken Snell \(MVP\)" > <kthsneisll...@ncoomcastt.renaetl> wrote: [quoted text clipped - 127 lines] > > Thanks so much. meghanwh@gmail.com - 15 Oct 2007 18:55 GMT On Oct 15, 1:41 pm, "Ken Snell \(MVP\)" <kthsneisll...@ncoomcastt.renaetl> wrote:
> If I'm understanding your setup correctly, I think you can get your desired > result if you put another textbox in the Detail section of the subform (name [quoted text clipped - 143 lines] > > > Thanks so much. I tried that and am only getting #Error in the new text box. The subform is in datasheet view, does this have anything to do with it?
Ken Snell (MVP) - 15 Oct 2007 19:22 GMT My error:
=DSum("Amount", "tblBudgetCategories", "[BudgetGoalNumber] Like " & [BudgetGoalNumber] & "*")
 Signature Ken Snell <MS ACCESS MVP>
> On Oct 15, 1:41 pm, "Ken Snell \(MVP\)" > <kthsneisll...@ncoomcastt.renaetl> wrote: [quoted text clipped - 159 lines] > I tried that and am only getting #Error in the new text box. The > subform is in datasheet view, does this have anything to do with it? meghanwh@gmail.com - 15 Oct 2007 20:36 GMT On Oct 15, 2:22 pm, "Ken Snell \(MVP\)" <kthsneisll...@ncoomcastt.renaetl> wrote:
> My error: > [quoted text clipped - 173 lines] > > I tried that and am only getting #Error in the new text box. The > > subform is in datasheet view, does this have anything to do with it? I'm still getting the error. Could this have anything to do with the fact that the subform and the form have different recordsources?
Ken Snell (MVP) - 15 Oct 2007 20:46 GMT OK - I've reread your post, and let's try this:
=DSum("Amount", "tblBudget", "[BudgetGoalNumber] Like '" & [BudgetGoalNumber] & "*'")
 Signature Ken Snell <MS ACCESS MVP>
>> > I tried that and am only getting #Error in the new text box. The >> > subform is in datasheet view, does this have anything to do with it? > > I'm still getting the error. Could this have anything to do with the > fact that the subform and the form have different recordsources? meghanwh@gmail.com - 15 Oct 2007 21:10 GMT On Oct 15, 3:46 pm, "Ken Snell \(MVP\)" <kthsneisll...@ncoomcastt.renaetl> wrote:
> OK - I've reread your post, and let's try this: > [quoted text clipped - 15 lines] > > I'm still getting the error. Could this have anything to do with the > > fact that the subform and the form have different recordsources? Oh that's fantastic. So that total is not saved anywhere, right? I'm wondering if it's possible to get that total amount listed on a different form.
Ken Snell (MVP) - 15 Oct 2007 21:41 GMT > On Oct 15, 3:46 pm, "Ken Snell \(MVP\)" > <kthsneisll...@ncoomcastt.renaetl> wrote: [quoted text clipped - 21 lines] > wondering if it's possible to get that total amount listed on a > different form. You'll need to provide more details about "different form" in terms of what the form is, is it open while your current form is open, etc. But is there a reason why you can't just calculate that sum whenever you want to show it?
 Signature
Ken Snell <MS ACCESS MVP>
meghanwh@gmail.com - 15 Oct 2007 21:56 GMT On Oct 15, 4:41 pm, "Ken Snell \(MVP\)" <kthsneisll...@ncoomcastt.renaetl> wrote:
> <megha...@gmail.com> wrote in message > [quoted text clipped - 33 lines] > Ken Snell > <MS ACCESS MVP> There's a group of forms, frmMainGoals, fmrLevel2Goals, frmLevel3Goals, etc. On those forms there is a button which opens frmBudgetForm. There's no reason why the budget total can't be calculated each time you open frmBudgetForm, but the client would like to see the total on frmMainGoals (etc.). If it's not possible then that's fine too, I can explain to him that it's not possible.
Ken Snell (MVP) - 16 Oct 2007 15:08 GMT >> > Oh that's fantastic. So that total is not saved anywhere, right? I'm >> > wondering if it's possible to get that total amount listed on a [quoted text clipped - 17 lines] > to see the total on frmMainGoals (etc.). If it's not possible then > that's fine too, I can explain to him that it's not possible. I don't have a good mental picture of all these forms' layout/content, so I cannot give you a firm answer. However, it's likely that you could put a textbox on the frmMainGoals form that would do someething similar, using similar expression except that you probably need to change the last field name to the one that is on frmMainGoals:
=DSum("Amount", "tblBudget", "[BudgetGoalNumber] Like '" & [YouNeedToPutCorrectFieldNameHere] & "*'")
 Signature
Ken Snell <MS ACCESS MVP>
meghanwh@gmail.com - 18 Oct 2007 04:50 GMT On Oct 16, 10:08 am, "Ken Snell \(MVP\)" <kthsneisll...@ncoomcastt.renaetl> wrote:
> <megha...@gmail.com> wrote in message > [quoted text clipped - 34 lines] > Ken Snell > <MS ACCESS MVP> Thanks so much. One more quick question. I have a field on a report, it's a text box: ="Budget: " & (DSum("Amount","tblBudget","[BudgetGoalNumber] Like '" & [GoalNumber] & "*'"))
Is there any way to get the numerical part formatted as currency? Thanks!
Ken Snell (MVP) - 18 Oct 2007 13:43 GMT > Thanks so much. One more quick question. I have a field on a report, > it's a text box: [quoted text clipped - 3 lines] > Is there any way to get the numerical part formatted as currency? > Thanks! ="Budget: " & Format(DSum("Amount","tblBudget","[BudgetGoalNumber] Like '" & [GoalNumber] & "*'"), "Currency")
 Signature Ken Snell <MS ACCESS MVP>
meghanwh@gmail.com - 19 Oct 2007 04:32 GMT On Oct 18, 8:43 am, "Ken Snell \(MVP\)" <kthsneisll...@ncoomcastt.renaetl> wrote:
> <megha...@gmail.com> wrote in message > [quoted text clipped - 15 lines] > Ken Snell > <MS ACCESS MVP> Thanks Ken. Now, I copied the frmBudgetForm for a payments form frmPaymentForm. frmPaymentForm is based on qryPayments:
SELECT tblPayments.PaymentID, tblPayments.PaymentGoalNumber, tblPayments.Amount, tblPayments.BudgetCategory, tblPayments.Vendor, tblPayments.Date, tblPayments.[Vendor's Invoice] FROM tblPayments;
When I click on the payments form button on each form, it only inserts the proper goal number IF there's already a payment for that specific Payment Goal Number. I'm a bit puzzled because this works perfectly on the frmBudgetForm, regardless of if there's a previous budget item or not. Isn't there a way to get it to put the correct Payment Goal Number in the subform on frmPaymentForm no matter if there's a previous payment or not? Thanks.
Ken Snell (MVP) - 20 Oct 2007 22:58 GMT I'm sorry, but I am not understanding your setup here. Can you explain more details about what you're doing with this new form, how you navigate to it (code that you're using to open it, for example), etc.? We were discussing how to show subtotals of goals and subgoals, and now we appear to be discussing how to edit the data?
 Signature Ken Snell <MS ACCESS MVP>
> Thanks Ken. Now, I copied the frmBudgetForm for a payments form > frmPaymentForm. frmPaymentForm is based on qryPayments: [quoted text clipped - 11 lines] > Payment Goal Number in the subform on frmPaymentForm no matter if > there's a previous payment or not? Thanks. meghanwh@gmail.com - 20 Oct 2007 00:08 GMT On Oct 18, 8:43 am, "Ken Snell \(MVP\)" <kthsneisll...@ncoomcastt.renaetl> wrote:
> <megha...@gmail.com> wrote in message > [quoted text clipped - 15 lines] > Ken Snell > <MS ACCESS MVP> One question on the DSum. If there's nothing entered for a particular GoalNumber, it returns the sum of all the BudgetGoalNumbers instead of just saying Null or zero. Is there any way to fix this? Thanks!
Ken Snell (MVP) - 20 Oct 2007 23:00 GMT Sure:
="Budget: " & IIf(Len([GoalNumber] & "")>0, Format(DSum("Amount","tblBudget","[BudgetGoalNumber] Like '" & [GoalNumber] & "*'"), "Currency")," no goal number entered")
 Signature Ken Snell <MS ACCESS MVP>
> On Oct 18, 8:43 am, "Ken Snell \(MVP\)" > <kthsneisll...@ncoomcastt.renaetl> wrote: [quoted text clipped - 22 lines] > GoalNumber, it returns the sum of all the BudgetGoalNumbers instead of > just saying Null or zero. Is there any way to fix this? Thanks!
|
|
|