A
Amit
Windows XP, MS Access 2K
=========================
Hi,
(this is somewhat long, so please have patience. I didn't
want to leave out any details.)
I have a main form (frmInvoice) that has:
1. a button to "refresh" the form.
2. unbound text controls to display running total, and
numbers for the following - BudgetAmount, BudgetFeeSum,
InvoiceSum, CurrentBalance.
3. a subform (sfrmInvoiceItem) to enter invoice items.
Relationship:
-A budget has amount (BudgetAmount).
-A budget can have one or more fee associated with it, sum
of which is (BudgetFeeSum).
-A budget can have one or more invoices associated with it.
-An invoice can have one or more "invoice items"
associated with it, each "invoice item" having a dollar
amount, the sum of which is the InvoiceAmount.
-Sum of all the InvoiceAmounts for a Budget is the
InvoiceSum.
I'm displaying the BudgetAmount, BudgetFeeSum, InvoiceSum
and CurrentBalance on a tabcontrol page on frmInvoice. I'm
calculating them using DLookup and DSum in the "On
Current" event of the form. Except for CurrentBalance, for
which I'm using the "Control Source" on the form itself.
(CurrentBalance = [BudgetAmount] - [BudgetFeeSum] -
[InvoiceSum])
I have sfrmInvoiceItem on another page of the tabcontrol.
There is another unbound control that gives the
RunningTotal for the current invoice, by adding the
InvoiceItem amounts.
I have a button to refresh (Me. Requery) the running total
after I enter an invoice item.
Everything is working fine, and all the numbers are being
calculated correctly, EXCEPT that I have to press
the "refresh" button twice to refresh and update the
Budget information (InvoiceSum and CurrentBalance).
The RunningTotal gets updated when I click the button
once, but not the other controls, which are on the second
page of the tab control.
I'm not sure why this is happening, and how to correct
this, such that the Budget information is also updated
with the RunningTotal on a single-click.
Any help, pointers with an explanation will be much
appreciated. I've pretty much given up at this point...
Thanks!
-Amit
Here's the code from "OnClick" event of the "refresh"
button:
========================================================
Private Sub cmdRefresh_Click()
On Error GoTo Err_cmdRefresh_Click
Me.Dirty = False 'save the record
'save the current record number in the mainform
saverecnum = Me.CurrentRecord
'save the current record number in the subform
saverecnumsfrm = Me!sfrmInvoiceItem.Form.CurrentRecord
Me.Requery
'go to the record from which the button was clicked
DoCmd.GoToRecord , , acGoTo, saverecnum
'set focus to the subform
Me!sfrmInvoiceItem.SetFocus
'go to the record on the subform from which the button
'was clicked
DoCmd.GoToRecord , , acGoTo, saverecnumsfrm
Exit_cmdRefresh_Click:
Exit Sub
Err_cmdRefresh_Click:
MsgBox Err.Description
Resume Exit_cmdRefresh_Click
End Sub
========================================================
********************************************************
And, here's the code from "OnCurrent" event of the form:
(I've deleted some lines that are not relevant to the
controls in question)
=========================================================
Private Sub Form_Current()
.....
If Me.NewRecord Then
Me.txtBudgetAmount = 0
Me.txtBudgetFeeSum = 0
Me.txtInvoiceSum = 0
Me.InvoiceOtherCategoryDescr.Enabled = False
Me.cboPayeeID.Locked = True
Me.TabCtl13.Pages(1).Visible = False
Me.txtRunningTotal = 0
Me.InvoiceOtherCategoryDescr.Enabled = False
Me.Dirty = False
End If
Me.txtBudgetAmount = DLookup
("[BudgetAmount]", "tblBudget", _
"[BudgetItemID] = " & Me.BudgetItemID)
Me.txtBudgetFeeSum = DSum("[FeeAmount]", "tblBudget", _
"[BudgetItemID] = " & Me.BudgetItemID)
If IsNull(Me.txtAdCareFee) Then
Me.txtBudgetFee = 0
End If
Me.txtInvoiceSum = DSum
("[InvoiceAmount]", "tblInvoice", _
"[BudgetItemID] = " & Me.BudgetItemID)
If IsNull(Me.txtInvoiceTotal) Then
Me.txtInvoiceTotal = 0
End If
.....
'recalculate RunningTotal using SQL
....
End Sub
=========================================================
=========================
Hi,
(this is somewhat long, so please have patience. I didn't
want to leave out any details.)
I have a main form (frmInvoice) that has:
1. a button to "refresh" the form.
2. unbound text controls to display running total, and
numbers for the following - BudgetAmount, BudgetFeeSum,
InvoiceSum, CurrentBalance.
3. a subform (sfrmInvoiceItem) to enter invoice items.
Relationship:
-A budget has amount (BudgetAmount).
-A budget can have one or more fee associated with it, sum
of which is (BudgetFeeSum).
-A budget can have one or more invoices associated with it.
-An invoice can have one or more "invoice items"
associated with it, each "invoice item" having a dollar
amount, the sum of which is the InvoiceAmount.
-Sum of all the InvoiceAmounts for a Budget is the
InvoiceSum.
I'm displaying the BudgetAmount, BudgetFeeSum, InvoiceSum
and CurrentBalance on a tabcontrol page on frmInvoice. I'm
calculating them using DLookup and DSum in the "On
Current" event of the form. Except for CurrentBalance, for
which I'm using the "Control Source" on the form itself.
(CurrentBalance = [BudgetAmount] - [BudgetFeeSum] -
[InvoiceSum])
I have sfrmInvoiceItem on another page of the tabcontrol.
There is another unbound control that gives the
RunningTotal for the current invoice, by adding the
InvoiceItem amounts.
I have a button to refresh (Me. Requery) the running total
after I enter an invoice item.
Everything is working fine, and all the numbers are being
calculated correctly, EXCEPT that I have to press
the "refresh" button twice to refresh and update the
Budget information (InvoiceSum and CurrentBalance).
The RunningTotal gets updated when I click the button
once, but not the other controls, which are on the second
page of the tab control.
I'm not sure why this is happening, and how to correct
this, such that the Budget information is also updated
with the RunningTotal on a single-click.
Any help, pointers with an explanation will be much
appreciated. I've pretty much given up at this point...
Thanks!
-Amit
Here's the code from "OnClick" event of the "refresh"
button:
========================================================
Private Sub cmdRefresh_Click()
On Error GoTo Err_cmdRefresh_Click
Me.Dirty = False 'save the record
'save the current record number in the mainform
saverecnum = Me.CurrentRecord
'save the current record number in the subform
saverecnumsfrm = Me!sfrmInvoiceItem.Form.CurrentRecord
Me.Requery
'go to the record from which the button was clicked
DoCmd.GoToRecord , , acGoTo, saverecnum
'set focus to the subform
Me!sfrmInvoiceItem.SetFocus
'go to the record on the subform from which the button
'was clicked
DoCmd.GoToRecord , , acGoTo, saverecnumsfrm
Exit_cmdRefresh_Click:
Exit Sub
Err_cmdRefresh_Click:
MsgBox Err.Description
Resume Exit_cmdRefresh_Click
End Sub
========================================================
********************************************************
And, here's the code from "OnCurrent" event of the form:
(I've deleted some lines that are not relevant to the
controls in question)
=========================================================
Private Sub Form_Current()
.....
If Me.NewRecord Then
Me.txtBudgetAmount = 0
Me.txtBudgetFeeSum = 0
Me.txtInvoiceSum = 0
Me.InvoiceOtherCategoryDescr.Enabled = False
Me.cboPayeeID.Locked = True
Me.TabCtl13.Pages(1).Visible = False
Me.txtRunningTotal = 0
Me.InvoiceOtherCategoryDescr.Enabled = False
Me.Dirty = False
End If
Me.txtBudgetAmount = DLookup
("[BudgetAmount]", "tblBudget", _
"[BudgetItemID] = " & Me.BudgetItemID)
Me.txtBudgetFeeSum = DSum("[FeeAmount]", "tblBudget", _
"[BudgetItemID] = " & Me.BudgetItemID)
If IsNull(Me.txtAdCareFee) Then
Me.txtBudgetFee = 0
End If
Me.txtInvoiceSum = DSum
("[InvoiceAmount]", "tblInvoice", _
"[BudgetItemID] = " & Me.BudgetItemID)
If IsNull(Me.txtInvoiceTotal) Then
Me.txtInvoiceTotal = 0
End If
.....
'recalculate RunningTotal using SQL
....
End Sub
=========================================================