Link to home
Start Free TrialLog in
Avatar of kelsoR
kelsoRFlag for South Africa

asked on

Listbox from Table

Hi all,

I get a CSV file sent to me from various Clients on a monthly basic.
I then import this file as a Table object.

The problem is that each Clients file has diffrent field/column names - all code driven.
Eg: 1001 mean Group 1 with Catogery 001
There could be hunderds of codes but because they all use the same format (the 1st digit being the identifier) I need to group them accordingly on a Form or Report.

So creating a Listbox and setting the Row Source Type to "Field List" will give me all the fields names but that is not what I need. I need a Listbox for each of the 6 or so Groups.
So all field names starting with a '1' must be listed in a seperate Listbox named Group1.
The same goes for the other groups. All must feed off the same initial table containing all the field names but seperated by group.

The second thing I need to do it to also show the value (per staff member) contained in the field by group's catogery.

So the Main Form will be bound to a Staff List. And each Staff members will have diffrent catogeries and values.
So if I'm on Staff members 145, I should be able to see the 6 or so Listboxes containing the diffrent field name per group and then next to it the values for those fields.

1001 = $100        2006 = $400
1002 = $50          2018 = $500

Hope this makes sense.
PS: I attached a sample of a typical file I'm getting.

Any ideas anyone?
Kelso
WGEXHR---Copy.CSV
Avatar of Helen Feddema
Helen Feddema
Flag of United States of America image

After importing the CSV into a master table, you could make queries filtering the data in the master table by the first character in the field name, and use those queries as row sources for the different listboxes.  You could also alias the field names as needed in these queries, or make totals queries based on them to get totals or other calculations as needed.
Avatar of kelsoR

ASKER

Thanks Helen, but I'm batteling with step one - and that is to build a table containing all the field names of the master table. Else - how do I run the query on the 1st char without having the field name in a table.
From there I should be able to move in the direction you suggest yes.
Avatar of kelsoR

ASKER

I found this code which works 100% for the "Group1" but puts the same data in "Group2".
So somewhere I'm missing a "requery" command or something to clear it.

Dim rs As DAO.Recordset
Dim fld As DAO.Field
Dim strSQL As String
Dim strMsg As String
Dim strStart As String
strSQL = "Select * from WGEXHR"

Set rs = CurrentDb.OpenRecordset(strSQL)

''Group1
For Each fld In rs.Fields
If Left(fld.Name, 1) = "1" Then strMsg = strMsg & fld.Name & ";"
Next

strMsg = Left(strMsg, Len(strMsg) - 1)

Me.List1.RowSource = strMsg
Me.List1.RowSourceType = "value list"

''Group2
For Each fld In rs.Fields
If Left(fld.Name, 1) = "2" Then strMsg = strMsg & fld.Name & ";"
Next

strMsg = Left(strMsg, Len(strMsg) - 1)

Me.List2.RowSource = strMsg
Me.List2.RowSourceType = "value list"

Open in new window

Avatar of kelsoR

ASKER

Ahh - I missed a

strMsg = ""

Between the 2 sections. Works 100% for both groups now.

Next step is to show the values for the spesific staff member as explained in the original post above.
ASKER CERTIFIED SOLUTION
Avatar of kelsoR
kelsoR
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kelsoR

ASKER

Not sure if this is allowed but I answered my own quetions after batteling for long on the net.