An alternative way:
In a standard code module:
Code:
Option Compare Database
Option Explicit
Public Enum CashFlows
cfNone = 0
cfIncome
cfAsset
cfLiability
cfExpense
End Enum
Function CurrentFlow() As Long
On Error Resume Next
CurrentFlow = [Forms]![Form1]![fraFlows]
End Function
Function CashFlowToString(lngType As CashFlows) As String
CashFlowToString = Choose(lngType + 1, "None", "Income", "Asset", "Liability", "Expense")
End Function
Function CurrentFlowToString() As String
CurrentFlowToString = CashFlowToString(CurrentFlow())
End Function
Function CashFlowIncome() As Long
CashFlowIncome = cfIncome
End Function
Function CashFlowExpense() As Long
CashFlowExpense = cfExpense
End Function
Examples of usage:
TextboxControl Source: =CurrentFlowToString()
Conditional FormattingExpression Is: CurrentFlow() = CashFlowIncome()
Form2’s code
Code:
Option Compare Database
Option Explicit
Private Sub Form_Load()
Me.Caption = "Cash Flows (" & CurrentFlowToString() & ")"
End Sub
Private Sub Form_Open(Cancel As Integer)
If CurrentFlow() = cfNone Then
MsgBox "Please, choose a cash flow type first!", vbCritical, "Cash flows"
Cancel = -1
End If
End Sub
Query
Code:
SELECT fDate, Sum(fAmount) AS FlowAmount, CurrentFlowToString() AS CashFlow
FROM tblFlows
WHERE fType = CurrentFlow()
GROUP BY fDate;
OR
Code:
SELECT fDate, Sum(fAmount) AS Income
FROM tblFlows
WHERE fType = CashFlowIncome()
GROUP BY fDate;