473,388 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

MS Access - Query Help

Hi,

I Need to show a product code with a unique entry in a table.

Eg – Xxxxx Xxxx – Thai Chocolate Tea = XX-TCT

Regards
Jun 19 '15 #1
4 1597
Seth Schrock
2,965 Expert 2GB
I'm assuming that the Xxxxx Xxxx is one field and the Thei Chocolate Tea is another field? I don't know of a way to do this using only SQL. I think that you will have to build a function in VBA that will return the values you are wanting and then call this function from your query. The VBA function would look something like this:
Expand|Select|Wrap|Line Numbers
  1. Public Function GetInitials(FullText as String) As String
  2. Dim strWords() As String
  3. Dim strInitials As String
  4. Dim i As Integer
  5.  
  6. strWords = Split(FullText, " ")
  7.  
  8. For i = 0 To UBound(strWords)
  9.     strInitials = strInitals & Left(strWords(i), 1)
  10. Next
  11.  
  12. GetInitals = strInitals
  13. End Function
Jun 19 '15 #2
jforbes
1,107 Expert 1GB
Seth's approach is more straightforward, and I doubt this will be useful, but it might and I find it pleasant and slightly twisted at the same time to use RegEex. So using this function:
Expand|Select|Wrap|Line Numbers
  1. Public Function trimWithRegex(ByVal sTemp As String, ByRef sPattern As String) As String
  2.     Dim RegEx As Object
  3.     Set RegEx = CreateObject("VBScript.RegExp")
  4.     RegEx.Global = True
  5.     RegEx.Pattern = sPattern
  6.     trimWithRegex = RegEx.Replace(sTemp, "")
  7. End Function
This would be the results from the Immediate Window:
Expand|Select|Wrap|Line Numbers
  1. ?trimwithregex("Xxxxx Xxxx – Thai Chocolate Tea", "[^A-Z–]")
  2. XX–TCT
This is a pretty good site for developing RegEx Patterns: http://regexr.com/
Jun 19 '15 #3
zmbd
5,501 Expert Mod 4TB
Keep in mind that RegEx is not a referenced library by default installation in Access. This must either be late bound or the reference added under the VBA-Editor under tools>References>"MS VBScript Regular Expressions"

Ms2BSwagg: Actually, what you are asking for here is somewhat difficult to follow forcing us to guess as both Seth and Jforbes have done an admirable job.

If you are using newer versions of Access you might find the following to be helpful.... I use this style of string work quite often in Access to provide custom lot/serial numbers for customers... Sample expressions to extract portion of a text string in Access
Yes, these are used in the SQL/Query editor :)
Pay particular attention to the seventh and eighth examples. In the eighth example if there is no middle initial it will return an error.


Please help us to more fully understand what you are attempting to do here... are these codes fixed, are you updating a table, etc...

Help us to help you by providing some more context.
Jun 19 '15 #4
Hey guys, thanks to you all for the feedback. Will have to go and try out the different suggestions.
@zmbd i have a work in progress database that i have for a business and need to have it show the name of company (1st letter of the two names = XX and then the product name = TCT) bearing in mind the product name will be various lengths. I would send the file but is large and still incomplete, going thro it as i find errors.
Thanks again for the help.
Jun 24 '15 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: SkunkDave | last post by:
I have a table that has numerical ID. I want a query that will get the 20 highest IDs. So in other words the query would return the last 20 results entered. What would even be better is if...
3
by: Omavlana | last post by:
Hi, How to get the value as 0 insted of NULL if there is no data found in the database for a particular column in the following Access query. select col1, col2 from tab1; If there are null...
2
by: jwmckin | last post by:
I have 2 fields in 2 seperate tables with text strings as the data. The two fields do not have the same number of entries. I need to compare the larger of the 2 fields to the smaller field and look...
4
by: ritchielong | last post by:
I have a access query made up of 2 tables & . from the table circuits i am using fields & from sitenames i am using i need my query to create 2 indexed columns based on the and then on the...
1
by: Loc108 | last post by:
I have two tables: Assignment Table AsignmentID, AssignmentName, CourseID Submit Table SubmitID, StudentID,AssignmentID, Point For a particular student in a particular class, I want it to...
1
by: Jordan M. | last post by:
Hi, Hoping someone can help me find a solution to the following problem I have. I have a query that currently pulls the following information from Table A Project Name Milestone...
3
by: heckstein | last post by:
I have created a query in MS Access 2003 that is pulling training records for our company that includes training hour calculation. One field I am pulling is the instructor name. Many courses have...
5
by: somacore | last post by:
For my application I need to be able to compare items in a database and output how they're all related. For example: Ticket #1 Programs: AA39 FR08 AA05 Ticket #2 Programs: AA39 FR08
24
by: goalv | last post by:
Hi friends I am bit new to access , I want to make query for data which has not happened after repeated attempts...can any one help me I have following tables DATE STORE ID DATE...
5
by: titli | last post by:
I want to run a update query accApp.OpenCurrentDatabase sRawDatabaseName accApp.DoCmd.TransferText acImportDelim, "DataImportSpec", "tblRaw", sLocalDataFile, False accApp.DoCmd.RunSQL "Update...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.