简体   繁体   中英

MS Access VBA Function to

I have an MS Access query that I use to place orders for training documents for hospital sites. I have a table (tblEntSites) with all the sites and the abbreviations that each site uses for the naming convention of their classes. In order to determine which site is hosting training I need to extract the abbreviation from the "Class_Name" field of our schedule table. I have been using the below function (although this one is shortened as there are over 20 sites) with a select case statement to do this and it works fine. However we are constantly adding sites and abbreviations and each time we do this I need to go in and amend the code. What I would love to be able to do is put together a function that will look to "tblEntSites" instead of the select case statement below. So basically it would check strClassName against all of the abbreviations in the table and then return the abbreviation that is contained in strClassName. Thank you in advance for your help!

Public Function DetermineSite(strClassName As String) As String

Select Case True

    Case InStr(strClassName, "BMC")
        DetermineSite = "BMC"
    Case InStr(strClassName, "LCC")
        DetermineSite = "LCC"
    Case InStr(strClassName, "RPH")
        DetermineSite = "RPH"
    Case Else
        DetermineSite = "Other"
    End Select

End Function

Examples of the "Class_Name" field values, the abbreviation is not always in the same place:

ED Unit Coordinator LCC
Ambulatory Nurse 100 BMC (G5)
Ambulatory-HP Health Professional PT/OT 200 RPH (PGL)

试试这个:

  Dlookup("column name", "tbl name", "column name LIKE "*"" & strClassName & """*")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM