Solved

include comma in name in results of VBA statement query

Posted on 2014-11-11
3
272 Views
Last Modified: 2014-11-11
I have inherited a query that is created in VBA.  It is a simply select statement, "SELECT RSM FROM tblRSM".  Problem is that the names have a comma, for example, Smith, Sandra.  When the code runs the query, it recognizes the value in field(0), BUT it then assumes the value after the comma is field(1).  How do I get it to recognize the entire name value rather than it automatically assuming the value after the comma is another field?

Sandra
0
Comment
Question by:ssmith94015
  • 2
3 Comments
 
LVL 34

Accepted Solution

by:
PatHartman earned 500 total points
Comment Utility
I'm not sure what you are talking about.  Queries don't use commas to separate data.  Each field is an object.  You would only run into this issue if you were working with a linked or imported flat file.  If this is supposed to be a .csv file, it is not following the standard.  The standard says that text fields that include a delimiter must be enclosed in quotes.  So the file should look like:

some data, "Smith, Sandra", 1234, other data

Typically ALL text fields are enclosed in quotes so you are more likely to see:
"some data", "Smith, Sandra", 1234, "other data"

Access will except either the loosely or tightly formatted version but it will only create the tightly formatted version.

If you can't get the producer of the file to clean up his act and produce a conforming file, you have no alternative but to parse it yourself with VBA and good luck with that.  You will have to be aware of where in the string the extra comma will occur so you can put those two fields back together.  The big issue will be when the name field doesn't contain a comma.  For example, if it only contains Cher.  Then you will be missing a field.  Your only hope is that the data around the name field is identifiable because of what it contains so your code will be able to discern when name doesn't actually contain a comma.
0
 

Author Closing Comment

by:ssmith94015
Comment Utility
This explains a lot of the problem.  Since the original programmer created this in VBA to populate a list box, I simply commented out the code and in the property for records once, selected Table/Query and created the query there.  Works properly now.  Went back and did this for all the list boxes, reduces the code but still get the same results.  Thank you.

Sandra
0
 
LVL 34

Expert Comment

by:PatHartman
Comment Utility
Good choice.  That is a far better method.  In other programming environments, the equivalent to list/combos isn't bound so you needed code to fill the RowSource.  Luckily for us, Access combos and listboxes are bound to the RowSource so no code is needed.  So, programmers who learned VB first for example, tend to write a lot more code than they need to.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now