Separating text in a field

R

Robin Chapple

I have been supplied with data with the address in one field separated
by commas:

POBox, Suburb, State, Postcode

I need to have each of the values in separate fields.

I have succeeded in separating the POBox field but failed to progress
any further.

Advice welcome.

Thanks,

Robin Chapple
 
P

PC Datasheet

You could put the Address in a separte file (text file). Then you could
treat that file as a comma separated values file and use the TransferText
method to import. Each value would import separately. You could also link to
the file and your Access table would automatically bring in each value
separately.
 
J

Joe Allison

I would just open the document in Word, do a find and replace function. I
would find all commas (,) and replace it with a tab (^t). Save it as a .TXT
file. Open it in Excel and when the dialog box asks you for the delimiter,
select 'tab'. All the field headers will be in separate cells.

Joe Allison
Fenton, MI
 
F

fredg

I have been supplied with data with the address in one field separated
by commas:

POBox, Suburb, State, Postcode

I need to have each of the values in separate fields.

I have succeeded in separating the POBox field but failed to progress
any further.

Advice welcome.

Thanks,

Robin Chapple

What version of Access?
If your version supports the Split() function, copy and paste the
following into a Module.

Public Function ParseText(TextIn As String, x) As Variant
On Error Resume Next
Dim VAR As Variant
VAR = Split(TextIn, ",", -1)
ParseText = VAR(x)

End Function
====

Call it from a query:
POBox:parseText([Fullfield],0)
Suburb:parseText([Fullfield],1)
State:parseText([Fullfield],2)
PostCode:parseText([Fullfield],3)

See VBA help for all of the arguments available in this new function.

If you have an older version of access post back and I'll dig out that
code.
 
P

PC Datasheet

You don't need to do the tab thing. Excel will do the same thing with
commas!

Steve
PC Datasheet
 
R

Robin Chapple

I have Access 2002 SP3

What version of Access?
If your version supports the Split() function, copy and paste the
following into a Module.

Public Function ParseText(TextIn As String, x) As Variant
On Error Resume Next
Dim VAR As Variant
VAR = Split(TextIn, ",", -1)
ParseText = VAR(x)

End Function
====

Call it from a query:
POBox:parseText([Fullfield],0)
Suburb:parseText([Fullfield],1)
State:parseText([Fullfield],2)
PostCode:parseText([Fullfield],3)

See VBA help for all of the arguments available in this new function.

If you have an older version of access post back and I'll dig out that
code.

I have been supplied with data with the address in one field separated
by commas:

POBox, Suburb, State, Postcode

I need to have each of the values in separate fields.

I have succeeded in separating the POBox field but failed to progress
any further.

Advice welcome.

Thanks,

Robin Chapple
 
R

Robin Chapple

I did not explain fully. These four values are part of a record. There
are twenty other fields and the four values need to remain linked to
the ID.
 
J

John Nurick

Hi Robin,

I'd use a function like this


Public Function ParseByComma(V As Variant, Pos As Long) As Variant
If IsNull(V) Then
ParseByComma = Null
Else
On Error Resume Next
ParseByComma = Trim(Split(V, ",")(Pos))
If Err.Number <> 0 Then
'Probably there aren't enough fields
Err.Clear
ParseByComma = Null
End If
On Error GoTo 0
End If
End Function

and use it in calculated fields in a query like this (XXX is the
fieldname):

POBox: ParseByComma([XXX],0)

Suburb: ParseByComma([XXX],1)

and so on
 
R

Robin Chapple

Thanks John,

I'll let you know how it goes.

Hi Robin,

I'd use a function like this


Public Function ParseByComma(V As Variant, Pos As Long) As Variant
If IsNull(V) Then
ParseByComma = Null
Else
On Error Resume Next
ParseByComma = Trim(Split(V, ",")(Pos))
If Err.Number <> 0 Then
'Probably there aren't enough fields
Err.Clear
ParseByComma = Null
End If
On Error GoTo 0
End If
End Function

and use it in calculated fields in a query like this (XXX is the
fieldname):

POBox: ParseByComma([XXX],0)

Suburb: ParseByComma([XXX],1)

and so on

I have been supplied with data with the address in one field separated
by commas:

POBox, Suburb, State, Postcode

I need to have each of the values in separate fields.

I have succeeded in separating the POBox field but failed to progress
any further.

Advice welcome.

Thanks,

Robin Chapple
 
G

Guest

Where are the other twenty fields? Are they also part of a list separated by
commas? I would try saving the text file as a .csv file, which should open
by default in Excel. If it looks OK in Excel you could import it into
Access. I have used this method to import an address book into an Access
table.
 
R

Robin Chapple

The problem is in one of twenty one fields where the four subjects are
contained.

For speed I did just that and then imported it.

I will use the other technique when I am not so busy.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top