DSum Problem

D

DS

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
 
F

fredg

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.
 
D

DS

fredg said:
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.
Thanks Fred, your suggestions are all helpful...it is now working!
DS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Convert to SQL 4
DSUM Not Working 5
A Better Way 4
DSum Problem 4
DLookUp Trouble 3
No Records Then 4
Loop Question 2
Sum of SQL Statement 1

Top