Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Join Multiple CSV Int Strings to a display Lookup text using MSAccess Query or VBA

Posted on 2013-01-08
2
Medium Priority
?
556 Views
Last Modified: 2013-01-08
I have a database (ATTACHED) with 2 tables tblData and tblLookup.  The required values from the lookup table are accessed via a query (qryLookupID) and served as drop downs or multiple checkboxes for user selection, via Access Form or Web Application.

i am trying to join multiple INT IDs stored in a text field to their corresponding text values for dynamic display on a Form or as text for reporting.

In this example I have colours based on an INT ID stored in a text field as comma separated integers as shown in the CURRENT section below.  Database normalisation issues aside, how do I perform this join to display the word values in a label or a textbox as shown in the REQUIRED section.

For one table there may be 20+ similar lookups all drawn from a single self-referencing table.

A Local or Global VBA function is preferred but MSACCESS (2003) SQL is fine.

ANY VBA solution MUST NOT rely on a button click event. Just dynamic type events on forms.  The main use will be to display current records as words instead of numbers on forms or to display records as text on generated reports.

A sample form has been created with an unbound textbox for dynamic display.

CURRENT
1       1
1       1,2
1       1,2,3
1       1,2,3,5

REQUIRED      
1       Red
2       Red, Green
3       Red, Green, Blue
4       Red, Green, Blue, Brown

SQL or Code solutions other than MS ACCESS or VBA will be disregarded.
JoinMultipleCSVIDString.mdb
0
Comment
Question by:XGIS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 38757110
place this codes in the form's module


Private Sub Form_Current()
Me.Text4 = fncCombineLUID(Me.MulltiStringLUID)
End Sub

Function fncCombineLUID(str)
Dim sArr() As String, j As Integer, varStr As String
If str & "" = "" Then fncCombineLUID = Null: Exit Function
sArr = Split(str, ",")
For j = 0 To UBound(sArr)
    varStr = varStr & ", " & DLookup("LookupValue", "tblLookup", "LUID=" & CInt(Trim(sArr(j))))

Next
varStr = Mid(varStr, 3)
fncCombineLUID = varStr
End Function
JoinMultipleCSVIDStringRev.mdb
0
 
LVL 7

Author Closing Comment

by:XGIS
ID: 38757209
You're a genius capricorn1. Thankyou so much for your time. Works perfect and is highly adaptable.
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question