Solved

include comma in name in results of VBA statement query

Posted on 2014-11-11
3
298 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 38

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 38

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
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…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

623 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