Thanks, Jon.
I did exactly what you said, and I am now getting:
"Undefined Function 'TotalTime' in expression" when I try to preview
the
SQL Statement: Query Builder.
My Function is shown below:
Public Function TotalTime()
Dim DTimeFactor, RTimeFactor, FromA, ToA
FromA = [tblAirports.TimeZone]
ToA = [tblAirports_1.TimeZone]
If FromA = "Hawaii" Then DTimeFactor = 1
If FromA = "Alaska" Then DTimeFactor = 2
If FromA = "Pacific" Then DTimeFactor = 3
If FromA = "Mountain" Then DTimeFactor = 4
If FromA = "Central" Then DTimeFactor = 5
If FromA = "Eastern" Then DTimeFactor = 6
If ToA = "Hawaii" Then RTimeFactor = 1
If ToA = "Alaska" Then RTimeFactor = 2
If ToA = "Pacific" Then RTimeFactor = 3
If ToA = "Mountain" Then RTimeFactor = 4
If ToA = "Central" Then RTimeFactor = 5
If ToA = "Eastern" Then RTimeFactor = 6
TotalTime = DateAdd("h", RTimeFactor, DepartTime) - DateAdd("h",
DTimeFactor, ArrivalTime)
TotalTime = Format(TotalTime, "h:nn")
End Function
I have tried to break this function up into its components and enter
it
into the SQL Statement as individual fields, like this:
DTF:
IIf([tblAirports.TimeZone]="Hawaii",1,IIf([tblAirports.TimeZone]="Alaska",2,IIf([tblAirports.TimeZone]="Pacific",3,IIf([tblAirports.TimeZone]="Mountain",4,IIf([tblAirports.TimeZone]="Central",5,IIf([tblAirports.TimeZone]="Eastern",6))))))
RTF:
IIf([tblAirports].[TimeZone_1]="Hawaii",1,IIf([tblAirports].[TimeZone_1]="Alaska",2,IIf([tblAirports].[TimeZone_1]="Pacific",3,IIf([tblAirports].[TimeZone_1]="Mountain",4,IIf([tblAirports].[TimeZone_1]="Central",5,IIf([tblAirports].[TimeZone_1]="Eastern",6))))))
Now if I preview this, I'm asked for the Parameter Value for
[tblAirports].[TimeZone_1].
Do you have another suggestion?
John Vinson said:
I have a Public Function TotalTime(), which I call from a Text Box:
=[TotalTime]
I currently sort two bound fields. How do I include the Function
TotalTime() in my sort order, and how do I specify
Ascending/Descending
on this function? Where does the "code" go to do this?
For example, I'd like to sort as follows:
Field1 Ascending
TotalTime Ascending
Field3 Ascending
Thanks,
Bernie
Don't call it from a textbox - call it in the Query itself. Put a
call
to the function in an vacant Field cell:
TTime: TotalTime()
and simply sort by this field.
John W. Vinson[MVP]