UDF not working perfect in access

Y

yusuf

I create one UDF and it working perfect in access form but one I try to used
in access query it give me this message (run time error ‘424’: object
requiredâ€, so what problem if you can help in this matter
Thanks
Yusuf
 
B

boblarson

Can you post your code so we can see what might be wrong? It is very hard to
deduce anything about a specific error like this without the code that is
causing it.
 
Y

yusuf

Function GetSort(rng As Variant) As Variant


ElseIf rng.Value Like "*ABN-AMRO*" Then
GetSort = "ABN-AMRO BANK"

ElseIf rng.Value Like "*CITI BANK*" Then
GetSort = "CITI BANK"


ElseIf rng.Value Like "H.S.B.C*" Then
GetSort = "H.S.B.C.- BANK"


Else
GetSort = "CASH"


End If


End Function
 
B

boblarson

Is that the whole thing? You can't start an IF...Then...Else statement off
with an ElseIf.
 
M

Marshall Barton

yusuf said:
Function GetSort(rng As Variant) As Variant

ElseIf rng.Value Like "*ABN-AMRO*" Then
GetSort = "ABN-AMRO BANK"

ElseIf rng.Value Like "*CITI BANK*" Then
GetSort = "CITI BANK"


ElseIf rng.Value Like "H.S.B.C*" Then
GetSort = "H.S.B.C.- BANK"


In addition to the issue Bob identified, you can not use the
Value property of an argument. It might work in your form
because Access magically figures out that you are passing a
text box control in a variant instead of the text box's
value, but Access doesn't appear to be able to do that for a
field in a query.

I think all you need to do is get rid of the .Value and just
use:

ElseIf rng Like "*CITI BANK*" Then
 
Y

Yusuf

Sorry while copying I missed the first two lines , actually it is starting
with IF, and Mr. Marshall Answer it is right and working perfectly.
Thanks to all
 
B

boblarson

Glad to hear you got it working.
--
Bob Larson
Access World Forums Super Moderator
Utter Access VIP
Tutorials at http://www.btabdevelopment.com
__________________________________
If my post was helpful to you, please rate the post.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top