Solved

Data Array in MS-Access Database Field

Posted on 2014-03-18
5
1,299 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 119

Expert Comment

by:Rey Obrero
ID: 39938650
upload a copy of the excel file.
0
 
LVL 34

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

762 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

19 Experts available now in Live!

Get 1:1 Help Now