473,382 Members | 1,252 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,382 software developers and data experts.

vba function within Access query

fair Warning - Admittedly I'm far from an access expert, but I'm not a
beginner either.

I want to split a value into multiple parts as delimited by a character
- all as part of a query. For example, one specific column in a table
contains values like "eggs/ham/potato" and "toast/fruit" and as I run a
select query against this table, I want to split the above values into
"eggs", "ham", "potato" (3 values)and "toast","fruit" (2 values)

My research has led me to the VBA function Split() but I've been
unsuccessful in incorporating the function into a query.

Thank you for your time.

*** Sent via Developersdex http://www.developersdex.com ***
Jun 6 '06 #1
2 7663
If this is Access 2002 or 2003, you should be able to parse the first
element from field [d] with:
Split([d],"/")(0)

Access 2000 might have problems doing that.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"patrick beyries" <pa*************@keynote.com> wrote in message
news:V1****************@news.uswest.net...
fair Warning - Admittedly I'm far from an access expert, but I'm not a
beginner either.

I want to split a value into multiple parts as delimited by a character
- all as part of a query. For example, one specific column in a table
contains values like "eggs/ham/potato" and "toast/fruit" and as I run a
select query against this table, I want to split the above values into
"eggs", "ham", "potato" (3 values)and "toast","fruit" (2 values)

My research has led me to the VBA function Split() but I've been
unsuccessful in incorporating the function into a query.

Jun 6 '06 #2
On Tue, 06 Jun 2006 06:13:09 GMT, patrick beyries wrote:
fair Warning - Admittedly I'm far from an access expert, but I'm not a
beginner either.

I want to split a value into multiple parts as delimited by a character
- all as part of a query. For example, one specific column in a table
contains values like "eggs/ham/potato" and "toast/fruit" and as I run a
select query against this table, I want to split the above values into
"eggs", "ham", "potato" (3 values)and "toast","fruit" (2 values)

My research has led me to the VBA function Split() but I've been
unsuccessful in incorporating the function into a query.

Thank you for your time.

*** Sent via Developersdex http://www.developersdex.com ***


If you have Access 2000 or newer:
Copy and Paste the following into a Module:

Public Function ParseText(TextIn As String, X) As Variant
On Error Resume Next
Dim var As Variant
var = Split(TextIn, "/", -1)
ParseText = var(X)

End Function
===========

Then add 3 new columns in the query grid:

FirstCol:ParseText([FieldNamel],0)
SecondCol:ParseText([FieldNamel],1)
ThirdCol:ParseText([FieldNamel],2)

Change FieldName to what ever the actual field names is.

--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Jun 6 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: aa | last post by:
I have beem recommended to use the Nz() function in the ORDER BY part of an Access2000 stored query. The query runs correcly from within Access2000 Yet when ran from ASP, it causes an error: ...
2
by: Stephen Bowyer | last post by:
I have an Access 97 database, which we use with a VB5 front end. If I create a new query in the database, the string functions left, mid etc do not work. For example the query: CalcField:...
10
by: Phil Latio | last post by:
Probably not the best way to do this, but I'd appreciate it if someone could tell me why the following DOESN'T work; I have a function (code below) which returns a string based upon a supplied...
2
by: Wade | last post by:
I am pretty new to Access, especially writing code, but I found code on the web to do just what I want and it is posted below. It returns a field value from a previous record. I found the code at:...
2
by: k-man | last post by:
Hi: I have an MS Access query for a table called MyTable. One of my fields in the query is a custom field that looks like "MyField: = MyFunction(ID)" where ID is a field in MyTable. I have...
4
by: wrldruler | last post by:
Hello, First, I know it's against "Access Law" to save calculations in a table, but....I want/need to. I currently have sub-totals being calculated inside a form, using DMax, DCount, and...
3
by: Libber39 | last post by:
Hi everyone, Have a query on how to calculate the amount of weeks and days contained in a number in an access query. ie: the difference in days between 2 dates amounts to 17 days. I want to now...
2
by: rmmahara | last post by:
Hi Folks, I've been reading these forums for a while and now I'm in desperate need of help, so I thought I'd post! Background: I'm creating a Service Dashboard to track my team's adherence...
1
by: giovannino | last post by:
Dear all, I did a query which update a sequence number (column NR_SEQUENZA) in a table using a nice code (from Trevor !). 1) Given that I'm not a programmer I can't understand why...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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...

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.