Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1557
  • Last Modified:

Data Array in MS-Access Database Field

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
Earl Kelly
Asked:
Earl Kelly
1 Solution
 
Rey Obrero (Capricorn1)Commented:
upload a copy of the excel file.
0
 
PatHartmanCommented:
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
 
Gustav BrockCIOCommented:
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
 
Earl KellyAuthor Commented:
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
 
Gustav BrockCIOCommented:
That's what my function does. Of course, as you have changed the fields, you must modify the function accordingly.

/gustav
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now