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 December 16th, 2004, 12:24 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default Break up a String

I am having a Brain Cramp. I have a string containing a full name such as "John Smith". How can I break that up in VBA, so that I can get FirstName = "John" and SecondName = "Smith".

Thanks in advance

Mike

Mike
EchoVue.com
__________________
Mike
EchoVue.com
 
Old December 16th, 2004, 12:48 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Not to worry, my brain has uncramped.

If you use the Split function, it will load the various parts of the String into an array. The tricky part is that there is an occasional Middle Initial, so I am going to initialize the array with 3 elements and then check to see if the third is blank, and if so assume that there is only a first and last name.

Thanks for looking at this anyway - and Merry Christmas!!

Mike
EchoVue.com
 
Old December 16th, 2004, 04:21 PM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

I have used split to split arrays that have as many as five members, and sometimes only the first two have data. I check the array for nulls and then concatenate the string based on the nulls (leaving them out of course.)

Hope the cramps go away.



mmcdonal
 
Old December 16th, 2004, 06:27 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Well, the cramps went, but now they are back.

Here is an interesting problem. I am building a SQL string dynamically to retrieve the PK of a user name from a master names table. It works great until the users name is something like O'Brien or O'Donnell.

How can I get the following string to work if userName = "O'Brien"

SQL = "SELECT nam_PK from M_Names WHERE nam_Name = '" & userName & "'"



Mike
EchoVue.com
 
Old December 16th, 2004, 06:57 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Not to worry again,

I used chr(34) instead of the '. Hopefully my users will not use " in any of their data!!

Thanks

Mike
EchoVue.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Why there isn't a "break"? XVenus Java Basics 1 September 4th, 2007 06:37 AM
help with 'break' Manu Sharma Beginning PHP 3 March 15th, 2007 09:04 PM
line break problem XSLT 1 February 20th, 2006 11:18 AM
how do i break it up? kuehhc Beginning PHP 3 January 19th, 2005 09:52 AM
Unable to Break at Break point Girishbk VB.NET 2002/2003 Basics 0 January 18th, 2005 08:29 AM





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