What version of Access?
I would add the additional fields to the table and then use an update
query to populate the new fields
First I would add the following function to a module.
Parse string into sections and get a specific section / Item / token
from the string
Public Function getSection(strIn, _
Optional strDelimiter As String = ";", _
Optional intSectionNumber As Integer = 1)
'==============================================================
' Procedure : getSection
' Author : John Spencer
' Purpose : Return section of string
' Access 2000 and later
'==============================================================
Dim strArray As Variant
If Len(strIn & vbNullString) = 0 Then
getSection = Null
Else
strArray = Split(strIn, strDelimiter, -1, vbTextCompare)
If UBound(strArray) >= intSectionNumber - 1 Then
If Len(strArray(intsectionNumber)-1) + "") = 0 then
getSection=Null
else
getSection = strArray(intSectionNumber - 1)
End If
Else
getSection = Null
End If
End If
End Function
Then I would populate the fields with
UPDATE SomeAddressTable
SET [Name] = GetSection(BigField,chr(13) & chr(10),1)
, [Name1]= GetSection(BigField,chr(13) & chr(10),2)
, [Address] = GetSection(BigField,chr(13) & chr(10),3)
, [City] = GetSection(BigField,chr(13) & chr(10),4)
, [State] = GetSection(BigField,chr(13) & chr(10),5)
Then I would run a second query to set the state and zipcode
UPDATE SomeAddressTable
SET [State] = Trim(LEFT([State], Instr(1,[State],"ZIP Code:")-1))
, [ZipCode] = Trim(Mid([State], Instr(1,[State],"ZIP Code:")+8))
WHERE [State] is not null and ZipCode is Null
'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
I have an address that has been pasted into the database as one big field. I
need to format it into individual fields so I can work with it. This is how
it is being pasted into the database:
NAME
NAME1
ADDRESS
CITY
STATE ZIP CODE: ZIP CODE
The words "ZIP CODE:" are actually copied into the database. The zip code
field may or may not have the +4 digits. This is being copied from an on-line
report. I can't do anything about it, I just need to work with it. Is there
anyone that can help me? I don't know VB.