Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 3rd, 2008, 09:16 AM
Authorized User
 
Join Date: May 2007
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default Parsing query

Hi All,

Got a relatively easy one for all the experienced guys in the house. I've looked 15 pages deep in google searcheson several variations of split / parsing on the net before coming to ask, and can find something partway and dealing with it after the event in terms of database updating / repairing however not quite in terms of doing it as the user types

I want to split a postcode into two parts hidden away from the user for use elsewhere in the system in demographics reports.

The user will enter the postcode via a mask to keep things simple for them and this is to happen once they leave the field.

Its parsing it on the space between the outward and inward postcode parts as well as seperately the 1st digit of the inbound postcode part

If we take a couple of standard postcodes you'll get a better idea

txtprpostcode = "M27 4RG" to go into
txtgeopostcode ="M27"
txtlocpostcode = "M274"

txtprpostcode = "B3 4TH" to go into
txtgeopostcode ="B3"
txtlocpostcode = "B34"

I need to figure a way to do this as a routine on the current event for the form, activation event for a form as to update the whole database isn't really an option at the moment, though probably nice in the future.

I normally put non-visible fields dotted around the form to allow the use of

me.fieldname.value= x

which I find works better with access 2000's VBA, which I have to work with. rather than the INSERT command

 
Old June 3rd, 2008, 10:37 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

So you want to split the data on the space? You would need to do this with an array.

I would put this on the Before Insert and Before Update events of your data entry form, with these fields hidden: txtgeopostcode, txtlocpostcode, then add this code:

Dim PostArray As Variant
Dim sStart As String
Dim sGeoEnd As String
Dim sLocEnd As String

sStart = Me.txtprpostcode

PostArray = Split(sStart, " ")

sGeoEnd = PostArray(0)
sLocEnd = sGeoEnd & Left(PostArray(1), 1)

Me.txtgeopostcode = sGeoEnd
Me.txtlocpostcode = sLocEnd



Did that help?



mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old June 3rd, 2008, 10:39 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

You would probably want to do something like this, though:

If IsNull(Me.txtprpostcode) or Me.txtprpostcode = "" Then
   Exit Sub
Else
'rest of code

End If

Otherwise you may get a subscript out of range error if the field is empty.

mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old June 3rd, 2008, 10:56 AM
Authorized User
 
Join Date: May 2007
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hiya,

with the addition of the .value to the field names it works beautifully.

Don't know why however without the deambiguity this installation of access 2k has a fit on most things.

 
Old July 4th, 2008, 09:33 AM
Authorized User
 
Join Date: May 2007
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

further to my last there seems to be a slight prob with that code in its working

I have the following input mask on the txtprpostcode box, just in case that may be a factor:

>La99\ 0LL;0;#

The issue is when the postcode has a single digit at the front

e.g. CW1 4TF will result in both having the value CW1 instead of one field having CW1 and the other having CW14

if its CW11 4RD then it works fine giving CW11 and CW114

The issue is the double space and getting the vba to recognise its there.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Parsing question: robprell Perl 2 May 28th, 2010 09:51 AM
parsing xml kri_hegde XML 5 July 24th, 2007 11:37 AM
XML Parsing SCADA_Monkey XML 2 March 11th, 2007 03:20 PM
Parsing mwviola98 SQL Language 4 July 21st, 2005 10:35 AM
Parsing in PHP Walter G Pro PHP 2 August 14th, 2003 01:54 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.