My DMax expression doesn't seem to work. I think the problem is with the
and clauses. Any help appreciated
Thanks
DS
Private Sub Form_Open(Cancel As Integer)
If Me.CheckType = 7 Then
Me.Text34 = DSum("[Expr4]", "DollDetailsQ", "SalesID =
Forms!ButtonSales!SalesID and Taxed = True")
Else:
Me.Text34 = DSum("[Expr4]", "DollDetailsQ", "SalesID =
Forms!ButtonSales!SalesID And Taxed = True And Inclusive = True") *
Me.SalesTax
End If
End Sub
1) Words like "doesn't seem to work" gives us absolutely no worth
while information. In the future, please let us know what does
happen? What does not happen? What do you expect to happen? What
datatypes are the various fields used in the expression? What is the
name of the form in which this code is placed? Do you get a VBA Error,
or #Error shown in the control? What is your Access version number?
..... Answers to those types of questions are worth while. Help us
help you.
2) The Form Open event is too early in the loading process to
determine the value of a control. Use the Form Load event instead (or
Current event if applicable).
3) The syntax needed in the where clause of a DSum() is dependent upon
the datatype of the criteria field.
Look up Where Clause + "Restrict Data to a subset of records"
in VBA help.
4) You need to place the variables outside of the quotes.
5) If this code is placed, as I suspect, on the [ButtonSales] form,
you can substitute the Me! keyword in place of forms!ButtonSales.
6) Try, in the form Load event (assuming [SalesID] is a number
datatype and [Taxed] and [Inclusive] are Yes/No check box datatype):
Me.Text34 = DSum("[Expr4]", "DollDetailsQ", "[SalesID] = " &
Me![SalesID] & " And [Taxed] = True")
Else:
Me.Text34 = DSum("[Expr4]", "DollDetailsQ", "[SalesID] = " &
Me![SalesID] & " And [Taxed = True And [Inclusive] = True") *
Me.SalesTax
If this code is not placed in the ButtonSales form, then you should
use the Forms!ButtonSales! syntax, not Me!. However, the ButtonSales
form must still be open when this form opens.