Parsing a Field

DeanRowe

Registered User.
Local time
Today, 21:19
Joined
Jan 26, 2007
Messages
142
Hi,

I'm looking for some help to parse or separate data from one field and copy it into different fields on my form.

I’ve written a PHP Script on my website that sends the data entered in a web form to me in an email, I currently send the data to myself in the following format:

Firstname,surname,address,postcode,telephone,emailaddress

However if it helps or makes the code easier in MS Access I can change PHP script so it comes to me in pretty much any format I choose, such as something like:

“Firstname””surname””address””postcode””telephone””emailaddress”

or

(Firstname)(surname)(address)(postcode)(telephone)(emailaddress)

or any other variation really. An example using the current format would be:

joe,bloggs,50 main street,NH3 4AS,01234 567890,joebloggs@gmail.com

On my form so I can copy the data sent in my emails into a text field (For example the field would be called [EmailRawFormat], then use code to separate it into the right fields on my form.

I was thinking a code along the following lines but wasn’t sure how to proceed

Me.FirstNameField.Value =
Me.SurnameField.Value =
Me.AddressField.Value =
Me.PostcodeField.Value =
Me.TelephoneField.Value =
Me.EmailAddressField.Value =

I’m not keen on linking my database to the webform using our server as it appears (I may be mistaken but I don’t want to chance it) that people have been trying to send viruses through the webform. I know our email filters detect the viruses and block them out but I wouldn’t want to expose our database to them directly.

There are lots of posts in this forum for importing csv files, which led me onto parsing, but most of them involve minor complications here and there. As I have the option of setting the format myself I was wondering if anyone could please recommend the best format to use and coding to parse the data.

To sum up: I have a text field on my form that contains raw data which I want to separate into relevant fields on my form. I can set the format of the raw data, but need help with the coding to separate it.

Any help would be greatly appreciated. Thank you for your time.

Dean.
 
The easiest way of parsing is to use the VBA function Split, which will return an array containing the parsed elements. You just need to tell Split what delimiter character you've used.

It might seem obvious, but don't use a delimiter character that could actually appear in the data. I once had to deal with the output from a Call Centre computer which would create comma-separated files with data elements consisting of large numbers which had commas as thousands separators. Tricky in that case to then separate the elements...
 
Cheers John,

You were a great help! I used the following code:

Me.Customer_Name.Value = Split(ImportCSV, ">")(0)
Me.Customer_Address.Value = Split(ImportCSV, ">")(1)
Me.Customer_Postcode.Value = Split(ImportCSV, ">")(2)

and changed the "," to a ">" so when a customer used a comma when typing their address it would still work.

Thank you very much indeed! You were a great help

Dean
 

Users who are viewing this thread

Back
Top Bottom