1

ACCDB file using VBA. I am looking for a specific folder in the path of the database location. It will always be 3 deep from the file, but the depth in the drive is variable. I grabbed the project path, split it, but can't find a function to reverse it. Is there a built-in function or do you have to code it yourself. I have looked around and surprisingly can't find the solution anywhere.

    Dim pth As String
    Dim apth As String
    pth = Application.CurrentProject.Path
    apth = Split(pth, "\")
    'Reverse array here
    apth = apth(2) 'Grab second index
    MsgBox (apth) 'confirm folder
    Call search_Project(apth)
3
  • Why not just grab the (length-1)th item? Is there some other reason you need to reverse it? Commented Aug 2, 2012 at 15:13
  • That seems like it would work. I am not new to programming, just VBA. Can you (anyone) recommend a good online resource for Access specific VBA. I am used to great online dictionaries for PHP and the like, but I haven't found anything similar for this. Commented Aug 2, 2012 at 15:19
  • This may be of some interest Access 2010 Developer Reference. As Tim Williams says, you can For i=UBound(Array) to 0 Step -1 Commented Aug 2, 2012 at 15:24

2 Answers 2

1

there are a couple issues with the code like you can declare a string and then try and use it as an array. Below is the modified using the length of the array and subtracting 3 to get the position you want. I also added a check to ensure the length of the array is atleast 3 elements. Removed the as String for apth as you want to use it as an array.

Dim pth As String
Dim apth
pth = Application.CurrentProject.Path
apth = Split(pth, "\")
'Reverse array here
If UBound(apth) >= 3 Then
apth = apth(UBound(apth) - 3)
End If
'Grab second index
MsgBox (apth) 'confirm folder
Call search_Project(apth)
Sign up to request clarification or add additional context in comments.

1 Comment

Had to change the "apth = " to a different string, but that works perfect. Thank you all!
1
apth = strReverse(Split(strReverse(pth),"\")(2)) 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.