Solved

Concatinating open number of fields & updating a table

Posted on 2009-03-30
2
275 Views
Last Modified: 2012-05-06
Decently I have inherited this on-going project, and need to re-work it unfortunately my bronchial pneumonia is kicking my butt at this time.
I get a file of bounced e-mail, the first 4 fields are fine the way they are the issues for the end user is the rest of the fields starting with field 5 thru whatever. The end user wants the remaining fields to be concatenated into one field. Each bounced e-mail files contains a different number of fields e.g. one file may contain fields 1 thru 19 the next may have fields 1 thru 89.
Is it possible and what would the statement look like to check the file for the maximum number of fields then concatenate fields 5 thru that max number field into one field
The current query looks like:
UPDATE Nolistdev201450 SET TEST_FIELD = IIF(ISNULL([field5]),'',IIF([field5]=' ', '',[field5] +' '))+
IIF(ISNULL([field6]),'',IIF([field6]=' ', '',[field6] +' '))+
IIF(ISNULL([field7]),'',IIF([field7]=' ', '',[field7] +' '))+
IIF(ISNULL([field8]),'',IIF([field8]=' ', '',[field8] +' '))+
IIF(ISNULL([field9]),'',IIF([field9]=' ', '',[field9] +' '))+
IIF(ISNULL([field10]),'',IIF([field10]=' ', '',[field10] +' '))+
IIF(ISNULL([field11]),'',IIF([field11]=' ', '',[field11] +' '))+
IIF(ISNULL([field12]),'',IIF([field12]=' ', '',[field12] +' '))+
IIF(ISNULL([field13]),'',IIF([field13]=' ', '',[field13] +' '))+
IIF(ISNULL([field14]),'',IIF([field14]=' ', '',[field14] +' '))+
IIF(ISNULL([field15]),'',IIF([field15]=' ', '',[field15] +' '))+
IIF(ISNULL([field16]),'',IIF([field16]=' ', '',[field16] +' '))+
IIF(ISNULL([field17]),'',IIF([field17]=' ', '',[field17] +' '))+
IIF(ISNULL([field18]),'',IIF([field18]=' ', '',[field18] +' '));

Since I have several hundred of these files to deal with I would like to load all of the files in a table in a MS Access database as fast & easy as possible. The alternate would be MS Excel spread sheet with it limitations.
I am also open to any suggestions.
0
Comment
Question by:mroberson
[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 11

Accepted Solution

by:
mildurait earned 250 total points
ID: 24019889
You can try something like this.
Public Sub TestUpdate()
    sql = GenUpdateStatment() 
    Call RunSqlStatement(sql)
End Sub
 
Public Sub TestSQL((
    Call debug.print(GenUpdateStatement())
End Sub
 
Public Sub RunSqlStatement(byVal sql as string)
    call docmd.setwarnings(false)
    call docmd.runsql(true)
    call docmd.setwarnings(false)
ENd Sub
 
 
Public Function GenUpdateStatment() as string
 
    dim sql as string
    Dim rs As DAO.Recordset
    Dim fld As DAO.Field
    Dim f as string
    dim i as long 
    i=0
    Set rs = CurrentDb.OpenRecordset("SELECT * FROM tblPrices WHERE 1=2")
    For Each fld In rs.Fields
        i = i + 1
        f = fld.name
        if i = 5 then sql = sql & "UPDATE Nolistdev201450 SET TEST_FIELD = IIF(ISNULL([" & f & "]),'',IIF([" & f & "]=' ', '',[" & f & "] +' '))" 
        if i>5 then sql = sql & " & IIF(ISNULL([" & f & "]),'',IIF([" & f & "]=' ', '',[" & f & "] +' '))"         
    Next
    rs.close
    set rs = nothing
    GenUpdateStatement = sql
 
End Function

Open in new window

0
 

Author Closing Comment

by:mroberson
ID: 31564351
with some modification was albel to use your code. One of the issues that had to be address that I was not aware of was some of the files come with enpty record or 2 that contain some ascii charter so those jam of the works But thanks for the help
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
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…

734 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