Roly Reefer
Registered User.
- Local time
- Today, 15:40
- Joined
- Jan 28, 2005
- Messages
- 37
I am learning VBA and have some code that i cant get to work. When the code runs on the combo box it doesn't pick up any of the values where it should. The code is definitely correct and i have tried a few things to get it working but nothing changes. In the four textboxes, avg, sum min, max 0 is always showing, despite showing up in the query as having sales. You can change that by removing the NZ part and before that it was coming up with an invalid use of null error.
Private Sub cboProductName_AfterUpdate()
'code to declare variables for the procedure
Dim strCriteria As String, strFieldName As String
Dim strFieldValue As String, strDomain As String
Dim strDomainField As String, sngAverage As Single
'code to assign values to declared variables
strFieldName = "ProductName"
strFieldValue = "cboProductName"
strDomain = "qryOrderDetails"
strDomainField = "Quantity"
strCriteria = strFieldName & "=" & Chr(34) & strFieldValue & Chr(34)
'code to calculate statistics using the domain aggregate functions
lblSum.Caption =Nz( DSum(strDomainField, strDomain, strCriteria), 0)
sngAverage = Nz(DAvg(strDomainField, strDomain, strCriteria), 0)
lblAvg.Caption = sngAverage
lblMax.Caption = Nz(DMax(strDomainField, strDomain, strCriteria), 0)
lblMin.Caption = Nz(DMin(strDomainField, strDomain, strCriteria), 0)
End Sub
Thanks very much for any help
Private Sub cboProductName_AfterUpdate()
'code to declare variables for the procedure
Dim strCriteria As String, strFieldName As String
Dim strFieldValue As String, strDomain As String
Dim strDomainField As String, sngAverage As Single
'code to assign values to declared variables
strFieldName = "ProductName"
strFieldValue = "cboProductName"
strDomain = "qryOrderDetails"
strDomainField = "Quantity"
strCriteria = strFieldName & "=" & Chr(34) & strFieldValue & Chr(34)
'code to calculate statistics using the domain aggregate functions
lblSum.Caption =Nz( DSum(strDomainField, strDomain, strCriteria), 0)
sngAverage = Nz(DAvg(strDomainField, strDomain, strCriteria), 0)
lblAvg.Caption = sngAverage
lblMax.Caption = Nz(DMax(strDomainField, strDomain, strCriteria), 0)
lblMin.Caption = Nz(DMin(strDomainField, strDomain, strCriteria), 0)
End Sub
Thanks very much for any help
Last edited: