Solved

include comma in name in results of VBA statement query

Posted on 2014-11-11
3
290 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 36

Accepted Solution

by:
PatHartman earned 500 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 36

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

740 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