Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

include comma in name in results of VBA statement query

Posted on 2014-11-11
3
Medium Priority
?
305 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 40

Accepted Solution

by:
PatHartman earned 2000 total points
ID: 40436377
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
ID: 40436401
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 40

Expert Comment

by:PatHartman
ID: 40436485
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

879 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