Re: Expression help in Query
- From: "tina" <nospam@xxxxxxxxxxx>
- Date: Sat, 25 Mar 2006 04:04:26 GMT
well, i don't really know. if you exported the query *with the function in
it* to another db, you also need to export the module that contains the
function. did you do that?
hth
"Lucien" <Lucien@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:6EE0E368-A4C1-4D0E-89C4-D70F16919CB7@xxxxxxxxxxxxxxxx
Tina, when I used your code it worked fine...but when I try to export mya
query to another database, it doesn't work because it says something about
Access 2000 and Access 2003. I am using 2003. What could the problem be.
--
Thanks,
Lucien
"tina" wrote:
10 ranges makes one heck of a nested IIf() statement. i'd probably write
databasecustom function that uses a Select Case statement, instead, as
Public Function isRange(ByVal lngNum As Long) As String
Select Case lngNum
Case 33 To 37
isRange = "33-37"
Case 51 To 100
isRange = "51-100"
Case Is > 250
isRange = "GT 250"
Case Else
IsRange = "Unknown value"
End Select
End Function
put the code into a standard module. if you don't have one in your
writealready, then from the db window, click on the Modules tab, click New,
savethe code *below* any text the already appears in the VBA window, and
procedurethe module with the name modPublicProcedures. (the module name is not
important - except that it must be different from the name of the
MasterAvailabilityData.SLOverReason,you put in it.)
change your SQL to
SELECT MasterAvailabilityData.OrderDate,
MasterAvailabilityData.ActualAvailPlant,
MasterAvailabilityData.AvailFailureCode,
IsRange([MasterAvailabilityData].[BranchItemTrans]) AS BrchItmTrans,
MasterAvailabilityData.ItemID, ItemDescriptions.Desc,
MasterAvailabilityData.RSL, MasterAvailabilityData.SSL,
MasterAvailabilityData.SLOverrideQuantity,
MasterAvailabilityData.SLOverrideType,
statement -MasterAvailabilityData.SeasonalCode, MasterAvailabilityData.SpinCode,
MasterAvailabilityData.SpecialItemCat
FROM MasterAvailabilityData INNER JOIN ItemDescriptions ON
MasterAvailabilityData.ItemID = ItemDescriptions.ItemID
WHERE (((MasterAvailabilityData.OrderDate) Between #1/1/2006# And
#1/31/2006#) AND ((MasterAvailabilityData.AvailFailureCode)<>0) AND
((Val([MasterAvailabilityData]![BranchItemTrans]))>9) AND
((MasterAvailabilityData.BranchServicesDistrict)="w6"))
ORDER BY MasterAvailabilityData.ActualAvailPlant,
MasterAvailabilityData.AvailFailureCode,
[MasterAvailabilityData]![BranchItemTrans] DESC;
note that i change the name of your field alias from BranchItemTrans to
BrchItmTrans, because i don't think you can alias a field to the same
fieldname. also, note that i didn't "vet" the rest of your SQL
willonly dealt with the "range" issue.
hth
"Lucien" <Lucien@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:580BD046-D012-4886-8F76-13F489C119F7@xxxxxxxxxxxxxxxx
I have a basic Access question. I am trying to create a query that
thatdisplay different results than what is in my table. I have a field
followingis:
Val([MasterAvailabilityData]![BranchItemTrans]) AS BranchItemTrans.
This field is full of numbers. I would like the query to do the
easyfor this field:
basically create an If .... Then expression.
If record is 34, then display 33-37
If record is 55, then display 51-100
If record is 260, the display GT 250....and so on.
I have 10 different ranges that I would like to display instead of the
actual numerical record. Is this possible?
Here is the SQL view that I have so far, and I am a beginner, so go
on
me:MasterAvailabilityData.SLOverReason,
SELECT MasterAvailabilityData.OrderDate,
MasterAvailabilityData.ActualAvailPlant,
MasterAvailabilityData.AvailFailureCode,
Val([MasterAvailabilityData]![BranchItemTrans]) AS BranchItemTrans,
MasterAvailabilityData.ItemID, ItemDescriptions.Desc,
MasterAvailabilityData.RSL, MasterAvailabilityData.SSL,
MasterAvailabilityData.SLOverrideQuantity,
MasterAvailabilityData.SLOverrideType,
MasterAvailabilityData.SeasonalCode, MasterAvailabilityData.SpinCode,
MasterAvailabilityData.SpecialItemCat
FROM MasterAvailabilityData INNER JOIN ItemDescriptions ON
MasterAvailabilityData.ItemID = ItemDescriptions.ItemID
WHERE (((MasterAvailabilityData.OrderDate) Between #1/1/2006# And
#1/31/2006#) AND ((MasterAvailabilityData.AvailFailureCode)<>0) AND
((Val([MasterAvailabilityData]![BranchItemTrans]))>9) AND
((MasterAvailabilityData.BranchServicesDistrict)="w6"))
ORDER BY MasterAvailabilityData.ActualAvailPlant,
MasterAvailabilityData.AvailFailureCode,
Val([MasterAvailabilityData]![BranchItemTrans]) DESC;
--
Thanks,
Lucien
.
- References:
- Re: Expression help in Query
- From: tina
- Re: Expression help in Query
- From: Lucien
- Re: Expression help in Query
- Prev by Date: Re: "null values" when importing from excel
- Next by Date: Re: Reconciling the worlds of Excel and Access
- Previous by thread: Re: Expression help in Query
- Next by thread: Re: Expression help in Query
- Index(es):
Relevant Pages
|