Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Parsing a string in Access
Tina 

10 years ago
I figured out how to use VBA and set up a Module in Access as follows:
Option Explicit

  Function CountElements(ByVal S) As Integer
  ' Counts the words in a string that are separated by semi-colons.

  Dim WC As Integer, Pos As Integer
     If VarType(S) > 9 Or Len(S) = 0 Then
       CountElements = 0
       Exit Function
     End If
     WC = 1
     Pos = InStr(S, ";")
     Do While Pos > 0
       WC = WC + 1
       Pos = InStr(Pos + 1, S, ";")
     Loop
     CountElements = WC
  End Function

  Function GetWord(ByVal S, Indx As Integer)
  ' Returns the nth word in a specific field.

  Dim WC As Integer, Count As Integer, SPos As Integer, EPos As Integer
     WC = CountElements(S)
     If Indx < 1 Or Indx > WC Then
       GetWord = Null
       Exit Function
     End If
     Count = 1
     SPos = 1
     For Count = 2 To Indx
       SPos = InStr(SPos, S, ";") + 1
     Next Count
     EPos = InStr(SPos, S, ";") - 1
     If EPos <= 0 Then EPos = Len(S)
     GetWord = Trim(Mid(S, SPos, EPos - SPos + 1))
  End Function

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/15/2026 5:36:12 AM. PLT: 1s