skinnybloke wrote:
How do I modify this code so that it will only do the replacement
based upon the value of another field on the same record.
I'm going to be a bit harsh in this, so apologies in advance and nothing
personal meant.
First of all, don't dim your variables halfway through the procedure.
It's piss poor coding practice.
I'm assuming this particular function is used in your SQL.
Assuming field TEST is a string, simply add another argument:
ChangeCategory(s As String, strGoAhead as string)
IN your query design grid, the calulated field would be:
NameOfField: ChangeCategory(NameOfField, TEST)
See below for rewrite:
i.e. it will replace "10091200" with "Womens Clothing" only if the
field TEST = "YES"
What you are showing here is the opposite, ie, "Womens Clothing" is
being replaced by "10091200". It's important to know how you're
communictaing - if you're not communicating well in plain NEglish or
whatever language, you can't expect to communicate with the computer
effectively!
ChangeCategory(s As String, strGoAhead as string)
Dim a() As String
Dim v As Variant
if strGoAhead = "YES" then
s = Replace(s, "Womens Clothing", "10091200")
s = Replace(s, "Womens Footwear", "10110000")
s = Replace(s, "Mens Clothing", "10061100")
s = Replace(s, "Mens Footwear", "10150000")
s = Replace(s, "Accessories", "10130900")
end if
'I assume the rest works OK
a() = Split(s, "<")
For Each v In a
ChangeCategory = ChangeCategory & Mid$(v, InStr(v, ">") + 1)
Next v
'Don't forget an error handler!
End Function
--
Tim
http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me