Solved

Data Array in MS-Access Database Field

Posted on 2014-03-18
5
1,342 Views
Last Modified: 2014-05-11
I am working with an older database and the programmer used a data field to place a data array and parse the data in different fields.    So for instance a text field with a 100 character with has information at different spaces.   For instance the field is laid out like this:

Spaces 1-10:  First Name
Spaces 10-20: Last name
Spaces 30-40:  Address
Space 40-50: Zip Code

So I need to put information from an excel spreadsheet into this table.   I would like to create a query to pull from this spreadsheet and input the data into the field in the table using the same array.   What syntax would I use to create this field using exact text spaces?
0
Comment
Question by:Earl Kelly
5 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39938650
upload a copy of the excel file.
0
 
LVL 35

Expert Comment

by:PatHartman
ID: 39938671
You can use the Space() function to pad the fields or you can redo the whole thing using a "no code" solution.  This seems very code intensive for no purpose.  You could link to the spreadsheet and export a fixed width text file.  You will need to go through the process once manually to make an export spec but there is no code involved.
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 39939031
You can use this function:
Public Function ArrayField(ByVal FirstName, ByVal LastName, ByVal Address, ByVal ZipCode) As String

    Dim strField    As String
    
    strField = Space(50)
    
    Mid(strField, 1) = Nz(FirstName)
    Mid(strField, 11) = Nz(LastName)
    Mid(strField, 31) = Nz(Address)
    Mid(strField, 41) = Nz(ZipCode)
    
    ArrayField = strField

End Function

Open in new window

Then:

Select
    SomeField,
    AnotherField,
    ArrayField([First Name], [Last Name], [Address], [ZipCode]) As NameAddressField
From
    xlsYourLinkedExcelData

/gustav
0
 
LVL 1

Author Comment

by:Earl Kelly
ID: 39944220
Thank you guys for your help.  

I need to clarify my question.   I can get the information from the field using the Mid but I need to put the information back in the field.   Here is my question:

First Name:    Julie
Last Name:    Smith
DL#:     K8094000

And the output should be in one field in Access like this:

Combined Field:   Julie     Smith     K8094000

I could do spaces after, but this is going to vary based on the information in the field.  The field can be up to 10 characters long.  

Thanks in advance for your help
0
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 39944555
That's what my function does. Of course, as you have changed the fields, you must modify the function accordingly.

/gustav
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 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