Hi Tom
Still not got there.
I have tried the Davg and dlookup but I keep getting an error can not find
field "Temp" or "selectDate" when I am looking at a query
here is a list of the some of the attempts I have tried
' Me![AvgTemp] = DLookup([SelectDate]![AvgTemp], [SelectDate],
[SelectDate]![TempDate] = Me![TempDateCombo] And [SelectDate]![TempTime] =
Me![TempTimeCombo])
'Me![Text34] = DLookup([temp]![CMM_06], "[temp]")
' AvgTemp = DLookup([selectdate]![AvgTemp], [selectdate])
'Me![AvgTemp] = DLookup([Temp]![CMM_06] + [Temp]![CMM_07] +
[Temp]![CMM_08] + [Temp]![CMM_10], [Temp], [SelectDate]![TempDate] =
Me![TempDateCombo] And [SelectDate]![TempTime] = Me![TempTimeCombo])
'AvgTemp = DLookup([Temp]![CMM_06] + [Temp]![CMM_07] + [Temp]![CMM_08] +
[Temp]![CMM_10] / 4, [Temp], Me![TempDateCombo] = [Temp]![TempDate] &
Me![TempTimeCombo] = [Temp]![TempTime])
I have tried just to bring in a fields to a combo box from a table or a
query bit still get the error from the domain argument
the reason I wanted the average is I have 4 fields in a table and need the
average of those fields at a particular time
Any more advise please.
I also do not understand DAO recordset (more reading for me)
Thanks
Jon
Tom Wickerath said:
Hi Jon,
You need to approach this in a different manner. You can use the domain
aggregrate function DAvg to calculate your average in the domain, or you
open
a recordset in VBA code. Here is more on using domain aggregate functions
(they all work in a similar manner):
DLookup Usage Samples
http://www.mvps.org/access/general/gen0018.htm
So, an example would look something like this:
Option Compare Database
Option Explicit
Private Sub butAvg_Click()
On Error GoTo ProcError
AvgTemp = DAvg("FieldName", "TableOrQueryName", "Criteria")
ExitProc:
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure butAvg_Click..."
Resume ExitProc
End Sub
Here is a method that uses a DAO recordset:
Option Compare Database
Option Explicit
Private Sub butAvg_Click()
On Error GoTo ProcError
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("SelectDate", dbOpenSnapshot)
If rs.RecordCount > 0 Then
AvgTemp = rs("AvgTemp")
End If
ExitProc:
'Cleanup
On Error Resume Next
rs.Close: Set rs = Nothing
db.Close: Set db = Nothing
Exit Sub
ProcError:
MsgBox "Error " & Err.Number & ": " & Err.Description, _
vbCritical, "Error in procedure butAvg_Click..."
Resume ExitProc
End Sub
Tom Wickerath
Microsoft Access MVP
http://www.access.qbuilt.com/html/expert_contributors.html
http://www.access.qbuilt.com/html/search.html
__________________________________________