PC Review


Reply
Thread Tools Rate Thread

Calling Module function in query

 
 
=?Utf-8?B?SGl0ZXNoIENoYXVoYW4=?=
Guest
Posts: n/a
 
      13th Nov 2007
Hi,
I am having a user defined function in module. i want to call in my select
statement. is it possible. if yes How?

Function Slab(SlabVal As Integer)
If SlabVal > 0 And SlabVal <= 20 Then
Slab = 1
ElseIf SlabVal > 20 And SlabVal <= 50 Then
Slab = 2
ElseIf SlabVal > 50 And SlabVal <= 100 Then
Slab = 3
ElseIf SlabVal > 100 Then
Slab = 4
End If
End Function

the above function i want to call in select statement like

select SlbValue,slab(slbvalue) from Incentive


regards,
hiteshc
 
Reply With Quote
 
 
 
 
=?Utf-8?B?QnJpYW4=?=
Guest
Posts: n/a
 
      13th Nov 2007
Try this:

Make sure your Function is Public, like this:

Public Function Slab(SlabVal As Integer) As Integer
If SlabVal > 0 And SlabVal <= 20 Then
Slab = 1
ElseIf SlabVal > 20 And SlabVal <= 50 Then
Slab = 2
ElseIf SlabVal > 50 And SlabVal <= 100 Then
Slab = 3
ElseIf SlabVal > 100 Then
Slab = 4
End If
End Function

Now, select like this:

SELECT Incentive.SlbValue, Slab([SlbValue]) As Slab from Incentive

In the query builder, the Slab field will look like this:

Slab:Slab([SlbValue])

In addition, if SlbValue could ever be null, the function variables will
need to be Variant types instead of Integers, and you will need to handle the
null value somewhere in the If...ElseIf statement.

"Hitesh Chauhan" wrote:

> Hi,
> I am having a user defined function in module. i want to call in my select
> statement. is it possible. if yes How?
>
> Function Slab(SlabVal As Integer)
> If SlabVal > 0 And SlabVal <= 20 Then
> Slab = 1
> ElseIf SlabVal > 20 And SlabVal <= 50 Then
> Slab = 2
> ElseIf SlabVal > 50 And SlabVal <= 100 Then
> Slab = 3
> ElseIf SlabVal > 100 Then
> Slab = 4
> End If
> End Function
>
> the above function i want to call in select statement like
>
> select SlbValue,slab(slbvalue) from Incentive
>
>
> regards,
> hiteshc

 
Reply With Quote
 
=?Utf-8?B?S2xhdHV1?=
Guest
Posts: n/a
 
      13th Nov 2007
Brian, I believe the way you have it coded it will choke on a circular
reference.
It is the Slab as Slab part:
SELECT Incentive.SlbValue, Slab([SlbValue]) As Slab from Incentive

It may be necessary to use a different name:
SELECT Incentive.SlbValue, Slab([SlbValue]) As SlabType from Incentive
--
Dave Hargis, Microsoft Access MVP


"Brian" wrote:

> Try this:
>
> Make sure your Function is Public, like this:
>
> Public Function Slab(SlabVal As Integer) As Integer
> If SlabVal > 0 And SlabVal <= 20 Then
> Slab = 1
> ElseIf SlabVal > 20 And SlabVal <= 50 Then
> Slab = 2
> ElseIf SlabVal > 50 And SlabVal <= 100 Then
> Slab = 3
> ElseIf SlabVal > 100 Then
> Slab = 4
> End If
> End Function
>
> Now, select like this:
>
> SELECT Incentive.SlbValue, Slab([SlbValue]) As Slab from Incentive
>
> In the query builder, the Slab field will look like this:
>
> Slab:Slab([SlbValue])
>
> In addition, if SlbValue could ever be null, the function variables will
> need to be Variant types instead of Integers, and you will need to handle the
> null value somewhere in the If...ElseIf statement.
>
> "Hitesh Chauhan" wrote:
>
> > Hi,
> > I am having a user defined function in module. i want to call in my select
> > statement. is it possible. if yes How?
> >
> > Function Slab(SlabVal As Integer)
> > If SlabVal > 0 And SlabVal <= 20 Then
> > Slab = 1
> > ElseIf SlabVal > 20 And SlabVal <= 50 Then
> > Slab = 2
> > ElseIf SlabVal > 50 And SlabVal <= 100 Then
> > Slab = 3
> > ElseIf SlabVal > 100 Then
> > Slab = 4
> > End If
> > End Function
> >
> > the above function i want to call in select statement like
> >
> > select SlbValue,slab(slbvalue) from Incentive
> >
> >
> > regards,
> > hiteshc

 
Reply With Quote
 
=?Utf-8?B?QnJpYW4=?=
Guest
Posts: n/a
 
      14th Nov 2007
Good point. That's what I get for posting a response in the middle of the
night.

"Klatuu" wrote:

> Brian, I believe the way you have it coded it will choke on a circular
> reference.
> It is the Slab as Slab part:
> SELECT Incentive.SlbValue, Slab([SlbValue]) As Slab from Incentive
>
> It may be necessary to use a different name:
> SELECT Incentive.SlbValue, Slab([SlbValue]) As SlabType from Incentive
> --
> Dave Hargis, Microsoft Access MVP
>
>
> "Brian" wrote:
>
> > Try this:
> >
> > Make sure your Function is Public, like this:
> >
> > Public Function Slab(SlabVal As Integer) As Integer
> > If SlabVal > 0 And SlabVal <= 20 Then
> > Slab = 1
> > ElseIf SlabVal > 20 And SlabVal <= 50 Then
> > Slab = 2
> > ElseIf SlabVal > 50 And SlabVal <= 100 Then
> > Slab = 3
> > ElseIf SlabVal > 100 Then
> > Slab = 4
> > End If
> > End Function
> >
> > Now, select like this:
> >
> > SELECT Incentive.SlbValue, Slab([SlbValue]) As Slab from Incentive
> >
> > In the query builder, the Slab field will look like this:
> >
> > Slab:Slab([SlbValue])
> >
> > In addition, if SlbValue could ever be null, the function variables will
> > need to be Variant types instead of Integers, and you will need to handle the
> > null value somewhere in the If...ElseIf statement.
> >
> > "Hitesh Chauhan" wrote:
> >
> > > Hi,
> > > I am having a user defined function in module. i want to call in my select
> > > statement. is it possible. if yes How?
> > >
> > > Function Slab(SlabVal As Integer)
> > > If SlabVal > 0 And SlabVal <= 20 Then
> > > Slab = 1
> > > ElseIf SlabVal > 20 And SlabVal <= 50 Then
> > > Slab = 2
> > > ElseIf SlabVal > 50 And SlabVal <= 100 Then
> > > Slab = 3
> > > ElseIf SlabVal > 100 Then
> > > Slab = 4
> > > End If
> > > End Function
> > >
> > > the above function i want to call in select statement like
> > >
> > > select SlbValue,slab(slbvalue) from Incentive
> > >
> > >
> > > regards,
> > > hiteshc

 
Reply With Quote
 
=?Utf-8?B?S2xhdHV1?=
Guest
Posts: n/a
 
      14th Nov 2007
No problem, just wanted the OP to be aware.
--
Dave Hargis, Microsoft Access MVP


"Brian" wrote:

> Good point. That's what I get for posting a response in the middle of the
> night.
>
> "Klatuu" wrote:
>
> > Brian, I believe the way you have it coded it will choke on a circular
> > reference.
> > It is the Slab as Slab part:
> > SELECT Incentive.SlbValue, Slab([SlbValue]) As Slab from Incentive
> >
> > It may be necessary to use a different name:
> > SELECT Incentive.SlbValue, Slab([SlbValue]) As SlabType from Incentive
> > --
> > Dave Hargis, Microsoft Access MVP
> >
> >
> > "Brian" wrote:
> >
> > > Try this:
> > >
> > > Make sure your Function is Public, like this:
> > >
> > > Public Function Slab(SlabVal As Integer) As Integer
> > > If SlabVal > 0 And SlabVal <= 20 Then
> > > Slab = 1
> > > ElseIf SlabVal > 20 And SlabVal <= 50 Then
> > > Slab = 2
> > > ElseIf SlabVal > 50 And SlabVal <= 100 Then
> > > Slab = 3
> > > ElseIf SlabVal > 100 Then
> > > Slab = 4
> > > End If
> > > End Function
> > >
> > > Now, select like this:
> > >
> > > SELECT Incentive.SlbValue, Slab([SlbValue]) As Slab from Incentive
> > >
> > > In the query builder, the Slab field will look like this:
> > >
> > > Slab:Slab([SlbValue])
> > >
> > > In addition, if SlbValue could ever be null, the function variables will
> > > need to be Variant types instead of Integers, and you will need to handle the
> > > null value somewhere in the If...ElseIf statement.
> > >
> > > "Hitesh Chauhan" wrote:
> > >
> > > > Hi,
> > > > I am having a user defined function in module. i want to call in my select
> > > > statement. is it possible. if yes How?
> > > >
> > > > Function Slab(SlabVal As Integer)
> > > > If SlabVal > 0 And SlabVal <= 20 Then
> > > > Slab = 1
> > > > ElseIf SlabVal > 20 And SlabVal <= 50 Then
> > > > Slab = 2
> > > > ElseIf SlabVal > 50 And SlabVal <= 100 Then
> > > > Slab = 3
> > > > ElseIf SlabVal > 100 Then
> > > > Slab = 4
> > > > End If
> > > > End Function
> > > >
> > > > the above function i want to call in select statement like
> > > >
> > > > select SlbValue,slab(slbvalue) from Incentive
> > > >
> > > >
> > > > regards,
> > > > hiteshc

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling a function in another module =?Utf-8?B?QmFyYiBSZWluaGFyZHQ=?= Microsoft Excel Programming 4 7th Nov 2006 03:16 PM
Calling a function (module) from code =?Utf-8?B?RG9yY2k=?= Microsoft Access Form Coding 7 18th May 2006 04:07 AM
calling a module function =?Utf-8?B?SGxld2lz?= Microsoft Access Form Coding 5 23rd Mar 2006 08:33 PM
Calling a function in a Form module from a Query - is this possible Peter R. Fletcher Microsoft Access Forms 4 14th Apr 2004 08:03 AM
Calling VBA function that is in another module Jag Man Microsoft Excel Programming 2 7th Jan 2004 03:37 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:20 PM.