Results 1 to 3 of 3
  1. #1
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    287

    Creating a function - using 2 fields from a table

    Hey guys,

    I am pretty new writing functions. I have a query built on a table. 2 of the fields of this table are [MNR_CD] and [VE_CD], both are text (minor code and vendor code are what these fields are fore). I want to build a function that uses both of those controls, but I don't know how to do it. Read on for more details.

    We are rebuilding our entire minor code system, think of it as a dewey decimal system, of sorts. It is currently 4 characters long, and we are switching to a 6 number system. I am writing a function for each digit of the new system, then concatenating them together. The 4th digit of the new system is used for manufacturer. The english version of this function is "If the vendor code is ASHL or TMPR then the output should be 1 or 5 (respectively). If the vendor code is SEAL, look at the minor code. if the minor code is 8503, the output should be 3 and if the minor code is 8504, the output should be 4."



    This is a very simplified version of what I am trying to do. There will be 8 possibilities. But if you can show me how to do that in a function. The function currently is
    Code:
    Public Function Fourth(OldMinor As String) As Integer
    
    
    Select Case OldMinor
        Case "8900"
            Fourth = 5
        Case "8504"
            Fourth = 4
        Case "8503"
            Fourth = 3
        Case "8501"
            Fourth = 2
        Case "8502"
            Fourth = 3
        Case Else
            Fourth = 9
    End Select
    In the query I have "4thDigit: Fourth([MNR_CD])"

    I just don't know how to get the function to also reference another field.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,850
    snipe,

    We need a little more info. Perhaps some samples that describe where minor and vendor codes fit into the picture.

    A function with 2 parameters would be defined along the lines of

    Function MyFunction (Parm1 as string, Parm2 as string) as Integer
    ..
    ..
    ...code/logic here

    MyFunction = result of your manipulation

    exit Function
    ErrorHandler:
    Error code here
    ..
    End Function

  3. #3
    snipe's Avatar
    snipe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2013
    Posts
    287
    Ugh.. I need more coffee before I start coding. Didn't even realize you could do "(Parm1 as string, Parm2 as string)"

    That already solved my problem.

    Thanks orange!


Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 05-10-2012, 10:32 AM
  2. Replies: 12
    Last Post: 12-14-2011, 08:04 PM
  3. Replies: 10
    Last Post: 11-05-2011, 11:41 AM
  4. Creating a search function
    By jlclark4 in forum Forms
    Replies: 7
    Last Post: 12-30-2010, 02:03 PM
  5. Creating an algorithm function.
    By NGLG in forum Access
    Replies: 0
    Last Post: 12-07-2008, 09:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums