Solved

Concatinating open number of fields & updating a table

Posted on 2009-03-30
2
277 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

623 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