Solved

include comma in name in results of VBA statement query

Posted on 2014-11-11
3
285 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 35

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 35

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
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…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

773 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