Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

creating a vba array function in Access

Posted on 2014-09-10
3
Medium Priority
?
385 Views
Last Modified: 2014-10-01
I have a field that I need to parse, there are 6 components to the field.  Each element is separated with a semi-colon. (I can, using a query, put quotes and a comma to separate the elements. (I actually did this, putting quote marks also at the beginning of the field and the end of the field, when the array called in the string, it added additional quotes at the beginning and the end))

here is the field data: "09/06/2014","21:00","24:00","67","Regular","3"

I want to create a function that will return one of the elements of the array.    here is a copy of the function (and versions thereof) I have tried and I receive the error
Run-time error '13':
type mismatch

Function ParseOtherDept(ByVal s As String, ByVal i As Integer) As String
        Dim strArry As Variant
        strArry = s
        ParseOtherDept = strArry(i)
End Function

I've also tried the following function which produced the following error
Compile error:  Can't assign to array
Function ParseField1(ByVal s As String, ByVal i As Integer) As String
    Dim WrdArray() As String
    Dim x As String
        WrdArray() = s
       x = ","
       ParseField1 = Split(WrdArray, x, i)

End Function

I can't seem to find the missing link - can someone please assist...I have a workaround but this solution would be so much cleaner and clear as to which element I'm extracting.

thanks in advance for any assist.
Regards,
0
Comment
Question by:SCMHC
[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 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 40314803
use thise codes
Function fnParseInfo(vString As Variant, idx As Integer, Optional Delimiter As String = ",") As String

   Dim myArray() As String
   myArray = Split(vString, Delimiter)

   If idx < 0 Or idx > UBound(myArray) + 1 Then

      fnParseInfo = ""

  Else

      fnParseInfo = myArray(idx - 1)

   End If

End Function

Open in new window



pass the string like this

?fnParseInfo("09/06/2014,21:00,24:00,67,Regular,3",3)

it will return  
24:00


.
0
 

Author Comment

by:SCMHC
ID: 40354545
thank you, thank you...this works perfectly just the way you coded it!!!!
Thanks again
regards,
Deby
0
 

Author Closing Comment

by:SCMHC
ID: 40354554
don't know what I was missing in any of the other functions I found, but this one is quick and easy...just copy and paste!!!
Thanks much.
Regards,
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

730 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