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

x
?
Solved

Concatinating open number of fields & updating a table

Posted on 2009-03-30
2
Medium Priority
?
283 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 750 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

10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
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 Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

705 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