Solved

Concatinating open number of fields & updating a table

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

912 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now