I have the following field defined in a query to allow me to sort based on among other things a numerical field called WAMI (employee.WAMI).
SortBy: IIf([forms]![frmMain]![opgSortBy]="1",val([employee].[wami]),IIf([forms]![frmMain]![opgSortBy]="2",[role].[employeeNumber],IIf([forms]![frmMain]![opgSortBy]="3",[employee].[surname],IIf([forms]![frmMain]![opgSortBy]="4",[employee].[fullname]))))
The above looks at an option group and bases its sort order on what was chosen. In the case of choosing 1, the sort order is WAMI which is a number field in a table.
The problem I have is that when the operator chooses 1 the sort order is based on the left-to-right text values so I get something like
111111 2 333
instead of
2 333 111111
The problem seems obvious in that the returned value of the query field is of data-type string, so I though the fix was to simply use the VAL function around the employee.wami statement however this makes no difference.
Below is the actually SQL statement rather than the query field value.
SELECT Employee.WAMI, Role.EmployeeNumber, Employee.FullName, Employee.SMS, Employee.DeletedRecord, IIf([forms]![frmMain]![opgSortBy]="1",Val([employee].[wami]),IIf([forms]![frmMain]![opgSortBy]="2",[role].[employeeNumber],IIf([forms]![frmMain]![opgSortBy]="3",[employee].[surname],IIf([forms]![frmMain]![opgSortBy]="4",[employee].[fullname])))) AS SortBy FROM Employee INNER JOIN Role ON Employee.WAMI = Role.WAMI WHERE (((Role.Region)=GetRegion()))