Share via

Function Issue

Anonymous
2012-07-11T16:39:34+00:00

Good morning.

In the following, the values are returned as Integer and I need them to be returned as Text.

How do I change this?  Any and all help will be most appreciated!!

Amy

Option Explicit

Function GetToken(stLn, stDelim)

         Dim iDelim As Integer, stToken As String

         iDelim = InStr(1, stLn, stDelim)

         If (iDelim <> 0) Then

            stToken = LTrim$(RTrim$(Mid$(stLn, 1, iDelim - 1)))

            stLn = Mid$(stLn, iDelim + 1)

         Else

            stToken = LTrim$(RTrim$(Mid$(stLn, 1)))

            stLn = ""

         End If

         GetToken = stToken

      End Function

Function InParam(Fld, Param)

         Dim stToken As String

         If IsNull(Fld) Then Fld = ""

         Do While (Len(Param) > 0)

            stToken = GetToken(Param, ",")

            If stToken = LTrim$(RTrim$(Fld)) Then

               InParam = -1

               Exit Function

            Else

               InParam = 0

            End If

         Loop

      End Function

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

3 answers

Sort by: Most helpful
  1. Anonymous
    2012-07-11T23:40:24+00:00

    I need them to be returned as Text.

    I doubt you do.  The GetToken function is used to parse the parameter, and by default is set to use a comma as the token.   The InParam function in effect returns a Boolean TRUE or FALSE (implemented as -1 or 0 in Access).

    These functions are used to simulate the IN operator in a query, which does not accept a parameter as its argument.  The parameter is a comma delimited string expression, the values of which can be numbers or text.  In this case, however, it is not necessary to enclose text values in the list in quotes as you might expect, so the function can be called in a query with:

    WHERE InParam([Fruit], [Enter fruit list:]) = TRUE

    entering something like Apples,Oranges,Pears as the parameter to return any row where the Fruit column contains any one of these values.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2012-07-11T17:08:24+00:00

    Okay...I made the changes and now it returns the field blank...?

    Was this answer helpful?

    0 comments No comments
  3. ScottGem 68,830 Reputation points Volunteer Moderator
    2012-07-11T16:48:10+00:00

    Change Get Token to 

    Function GetToken(stLn, stDelim) As String

    Do the same InParam, but Add:

    InParam = CStr(InParam)

    just before the end function.

    Was this answer helpful?

    0 comments No comments