A
Arvi Laanemets
Hi
On form fmMain is subform sfDeviceGroups with form fmDeviceGroups as source.
On form fmDeviceGroups is subform sfDevices with form fmDevices as source.
On form fmDeviceGroups are 2 unbound combobox controls: cbbDevGroup and
cbbUserLevel.
On form fmDevices is a navigation combobox cbbSelectDevice. At moment
devices list to select from depends on cbbDevGroup value from parent form:
SELECT a.DeviceID, _
Trim(Nz(b.LastName,"") & " " & Nz(b.ForeName,"")) & "; " & _
Trim(Nz(a.Producer,"") & " " &
IIf(Nz(a.Mark,"")="",Nz(a.Model,""),a.Mark)) & "; " & _
a.DeviceID AS DeviceInfo _
FROM tblITDevices AS a, tblUsers AS b _
WHERE (((b.TabN)=a.CurrUser) And _
((Left(a.DeviceID,1))=[Forms]![fmMain]![sfDeviceGroups]!txtDevGroup)) _
ORDER BY a.CurrUL, 2;
So long it works.
Now I need to apply a additional filter: cbbUserLevel can have 11 different
text values. Depending on value of cbbUserLevel, I want in cbbSelectDevice
displayed devices with field CurrUL equal to one of values in integer range
0 - 9, or all devices except CurrUL=9
I created an UDF, which uses cbbUserLevel value as parameter and returns
values in range 0-9 or 99.
Public Function GetUL(parSelection As String) As Integer
Select Case parSelection
Case "All except user level 9"
GetUL = 99
Case "User level 0"
GetUL = 0
Case "User level 1"
GetUL = 1
Case "User level 2"
GetUL = 2
Case "User level 3"
GetUL = 3
Case "User level 4"
GetUL = 4
Case "User level 5"
GetUL = 5
Case "User level 6"
GetUL = 6
Case "User level 7"
GetUL = 7
Case "User level 8"
GetUL = 8
Case "User level 9"
GetUL = 9
End Select
End Function
Now when I use this function as source for some unbound textbox control, it
works perfectly.
It also works, when I use it in some saved query, p.e.
SELECT a.DeviceID, _
Trim(Nz(b.LastName,"") & " " & Nz(b.ForeName,"")) & "; " & _
Trim(Nz(a.Producer,"") & " " & _
IIf(Nz(a.Mark,"")="",Nz(a.Model,""),a.Mark)) & "; " & _
a.DeviceID AS DeviceInfo _
FROM tblITDevices AS a, tblUsers AS b _
WHERE (((a.CurrUL)=GetUL("User level 1")) _
And ((b.TabN)=a.CurrUser) _
And ((Left(a.DeviceID,1))="A")) _
ORDER BY a.CurrUL, 2;
But when I use this function in combo's row source query, nothing is
returned! Here is an testing example, which by default must return all
devices from group, because default value of cbbUserLevel is "All except
level 9", so GetUL() must return 99:
SELECT a.DeviceID, _
Trim(Nz(b.LastName,"") & " " & Nz(b.ForeName,"")) & "; " & _
Trim(Nz(a.Producer,"") & " " &
IIf(Nz(a.Mark,"")="",Nz(a.Model,""),a.Mark)) & "; " & _
a.DeviceID AS DeviceInfo _
FROM tblITDevices AS a, tblUsers AS b _
WHERE (((a.CurrUL)<GetUL([Forms]![fmMain]![sfDeviceGroups]!cbbUserLevel)) _
And ((b.TabN)=a.CurrUser) _
And
((Left(a.DeviceID,1))=[Forms]![fmMain]![sfDeviceGroups]!txtDevGroup)) _
ORDER BY a.CurrUL, 2;
, which returns nothing. When I replace UDF with value 99, all is OK.
I also tried to use a calculated control with UDF as source, but it didn't
work also. Probably it isn't possible to refer to calculated control from
query - I remember I read something about it.
I have lost almost 2 days on this problem, and any help is welcome! Thanks
in advance!
On form fmMain is subform sfDeviceGroups with form fmDeviceGroups as source.
On form fmDeviceGroups is subform sfDevices with form fmDevices as source.
On form fmDeviceGroups are 2 unbound combobox controls: cbbDevGroup and
cbbUserLevel.
On form fmDevices is a navigation combobox cbbSelectDevice. At moment
devices list to select from depends on cbbDevGroup value from parent form:
SELECT a.DeviceID, _
Trim(Nz(b.LastName,"") & " " & Nz(b.ForeName,"")) & "; " & _
Trim(Nz(a.Producer,"") & " " &
IIf(Nz(a.Mark,"")="",Nz(a.Model,""),a.Mark)) & "; " & _
a.DeviceID AS DeviceInfo _
FROM tblITDevices AS a, tblUsers AS b _
WHERE (((b.TabN)=a.CurrUser) And _
((Left(a.DeviceID,1))=[Forms]![fmMain]![sfDeviceGroups]!txtDevGroup)) _
ORDER BY a.CurrUL, 2;
So long it works.
Now I need to apply a additional filter: cbbUserLevel can have 11 different
text values. Depending on value of cbbUserLevel, I want in cbbSelectDevice
displayed devices with field CurrUL equal to one of values in integer range
0 - 9, or all devices except CurrUL=9
I created an UDF, which uses cbbUserLevel value as parameter and returns
values in range 0-9 or 99.
Public Function GetUL(parSelection As String) As Integer
Select Case parSelection
Case "All except user level 9"
GetUL = 99
Case "User level 0"
GetUL = 0
Case "User level 1"
GetUL = 1
Case "User level 2"
GetUL = 2
Case "User level 3"
GetUL = 3
Case "User level 4"
GetUL = 4
Case "User level 5"
GetUL = 5
Case "User level 6"
GetUL = 6
Case "User level 7"
GetUL = 7
Case "User level 8"
GetUL = 8
Case "User level 9"
GetUL = 9
End Select
End Function
Now when I use this function as source for some unbound textbox control, it
works perfectly.
It also works, when I use it in some saved query, p.e.
SELECT a.DeviceID, _
Trim(Nz(b.LastName,"") & " " & Nz(b.ForeName,"")) & "; " & _
Trim(Nz(a.Producer,"") & " " & _
IIf(Nz(a.Mark,"")="",Nz(a.Model,""),a.Mark)) & "; " & _
a.DeviceID AS DeviceInfo _
FROM tblITDevices AS a, tblUsers AS b _
WHERE (((a.CurrUL)=GetUL("User level 1")) _
And ((b.TabN)=a.CurrUser) _
And ((Left(a.DeviceID,1))="A")) _
ORDER BY a.CurrUL, 2;
But when I use this function in combo's row source query, nothing is
returned! Here is an testing example, which by default must return all
devices from group, because default value of cbbUserLevel is "All except
level 9", so GetUL() must return 99:
SELECT a.DeviceID, _
Trim(Nz(b.LastName,"") & " " & Nz(b.ForeName,"")) & "; " & _
Trim(Nz(a.Producer,"") & " " &
IIf(Nz(a.Mark,"")="",Nz(a.Model,""),a.Mark)) & "; " & _
a.DeviceID AS DeviceInfo _
FROM tblITDevices AS a, tblUsers AS b _
WHERE (((a.CurrUL)<GetUL([Forms]![fmMain]![sfDeviceGroups]!cbbUserLevel)) _
And ((b.TabN)=a.CurrUser) _
And
((Left(a.DeviceID,1))=[Forms]![fmMain]![sfDeviceGroups]!txtDevGroup)) _
ORDER BY a.CurrUL, 2;
, which returns nothing. When I replace UDF with value 99, all is OK.
I also tried to use a calculated control with UDF as source, but it didn't
work also. Probably it isn't possible to refer to calculated control from
query - I remember I read something about it.
I have lost almost 2 days on this problem, and any help is welcome! Thanks
in advance!