Kamis, 21 Maret 2019

Re: [MS_AccessPros] How the get the path.

 

Dear Graham,

Sorry for not explaining my problems well enough to understand in my previous email.  I will give clear overview of the questions in the future.  Here's what I wanted to achieve with getting the path. I have a bound hyperlink textbox in a form. By dragging file from explorer to this box. I get relative path instead of actual path of the file. The next step is after-update event of this textbox, the file will be copied or moved to destination folder with name of the record ID. Since I didn't get the actually path, the copying or moving action got stuck. With your help, I am able to achieve this effect successfully. Thanks a gain.

Best Regards,
Kevin

On 21-Mar-2019 5:06 PM, 'Graham Mandeno' graham@mandeno.com [MS_Access_Professionals] wrote:
 

Hi Kevin

 

You're welcome!

 

Please remember in future to give us an overview of what you want to achieve, because that helps us to give you a holistic solution J

 

Best wishes,

Graham

 

From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com>
Sent: Thursday, 21 March 2019 21:12
To: MS_Access_Professionals@yahoogroups.com
Subject: Re: [MS_AccessPros] How the get the path.

 

 

Dear Graham,

I just test it. It works great! Thank you so very much!

Best Regards,
Kevin

On 21-Mar-2019 12:31 PM, graham@mandeno.com [MS_Access_Professionals] wrote:

 

Hi Kevin

 

It helps to give a bit more overview of what you are trying to achieve.  I'm going to have to guess that you have a field which contains a path which is relative to the location of your database (CurrentProject.Path).

 

So, let's say CurrentProject.Path is C:\Users\Documents\Databases\MyProject:

 

If the relative path is SubfolderA\SubfolderB, then the desired result is:

C:\Users\Documents\Databases\MyProject\SubfolderA\SubfolderB

 

If the relative path is ..\..\SubfolderC\SubfolderD, then the desired result is:

C:\Users\Documents\SubfolderC\SubfolderD

 

Is my assumption correct?

 

If so, then you should use a loop, checking for "..\" at the beginning of the relative path.  For as long as it is there, you use Mid() to strip it off and use ParentPath to go up another level from CurrentProject.Path.  When there are no more "..\" to be found, you append what is left of the relative path to what is left of CurrentProject.Path, with a backslash between.

 

(Please note that this is "air code" - I am writing it off the top of my head and haven't tested it!)

 

Dim strAbsolutePath as String

Dim strRelativePath as String

strAbsolutePath = CurrentProject.Path

strRelativePath = <some value from a field?>

Do While Left( strRelativePath, 3 ) = "..\"

    strAbsolutePath = ParentPath( strAbsolutePath )

    strRelativePath = Mid( strRelativePath, 4 )

Loop

strAbsolutePath = strAbsolutePath & "\" & strRelativePath

 

You could even put this code in a Function AddRelativePath( AbsPath as String, RelPath as String) as String

 

Best wishes,

Graham

 


---In MS_Access_Professionals@yahoogroups.com, <qingqinga@...> wrote :

Dear Graham,

I have one more question, Suppose the path is like this: "..\..\" Is that possible to count how many "..\" there is, if that it is possible, so combining the ParentPath function I will be able to get the actual path of a file with "..\" or "..\..\" or even more "..\..\..\". Thanks in advance.

Best Regards,
Kevin

On 21-Mar-2019 7:46 AM, graham@... [MS_Access_Professionals] wrote:

 

 

Hi Kevin

 

InStrRev() searches back from the end of a string until it finds a given character (or string) and it returns the position of that character.  You can use this to find the last backslash in the path, and then use the Left() function to cut off the end of the path, including the backslash you have found.

 

It pays to use Len(Path) - 1 to start your search one character back from the end, just in case the last character is already a backslash.

 

Now you should understand how this function works:

 

Public Function ParentPath(ByVal Path As String) As String

  ParentPath = Left(Path, InStrRev(Path, "\", Len(Path) - 1) - 1)

End Function

 

Best wishes,

Graham Mandeno [Access MVP 1996-2016]


---In MS_Access_Professionals@yahoogroups.com, <qingqinga@...> wrote :

Dear Duane,

Thanks a lot. Yes. That's exactly what I want. I have tried instrRew(), but I didn't get the result I  want. I only know a little about it. I'll try again and again to get the expected result.

Best Result,

Kevin

 

发自 WPS邮箱客戶端

"Duane Hookom duanehookom@... [MS_Access_Professionals]" <MS_Access_Professionals@yahoogroups.com>2019321 01:05写道:

 

Hi Kevin,

So you want the current project path without rightmost folder name?

If this is the case you can use InstrRev() function

 

Duane

 


From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com> on behalf of qingqinga qingqinga@... [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>
Sent: Wednesday, March 20, 2019 11:15 AM
To: MS_Access_Professionals@yahoogroups.com
Subject: Re: [MS_AccessPros] How the get the path.

 

Dear Domenico,

Thanks for your reply. My point is to only get the path without the folder where the current project locates. Desktop is not the case.

Best Regards,

Kevin

 

发自 WPS邮箱客戶端

"Domenico Cozzolino domcoz@... [MS_Access_Professionals]" <MS_Access_Professionals@yahoogroups.com>2019320 15:31写道:



 

path = Environ("USERPROFILE") & "\Desktop"

Ciao Domenico

 

Il giorno mer 20 mar 2019 alle ore 07:24 crystal 8 strive4peace2008@... [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> ha scritto:

 

hi Kevin,

'~~~~~~~~~~~~~~~~~~~
Function GetDesktopPath() As String
'170423 crystal
   Dim oShell As Object
   Set oShell = CreateObject("WScript.Shell")
   GetDesktopPath = oShell.SpecialFolders("Desktop")
   Set oShell = Nothing
End Function
'~~~~~~~~~~~~~~~~~~~

have an awesome day,
crystal

free code you can use in your projects
https://msaccessgurus.com/code.htm

On 3/20/2019 12:02 AM, Kevin qingqinga@...
[MS_Access_Professionals] wrote:
> Dear All,
>
> With CurrentProject.path, I got this: C:\Users\mrzha\Desktop\FileFolder,
> My question is how to get :"C:\Users\mrzha\Desktop" ? Thanks in advance.
>
> Best Regards,
> Kevin
>
>
>
> ------------------------------------
> Posted by: Kevin <qingqinga@...>
> ------------------------------------
>
>
> ------------------------------------
>
> Yahoo Groups Links
>
>
>

 

__._,_.___

Posted by: Kevin <qingqinga@yahoo.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (16)

Have you tried the highest rated email app?
With 4.5 stars in iTunes, the Yahoo Mail app is the highest rated email app on the market. What are you waiting for? Now you can access all your inboxes (Gmail, Outlook, AOL and more) in one place. Never delete an email again with 1000GB of free cloud storage.


SPONSORED LINKS
.

__,_._,___

Tidak ada komentar:

Posting Komentar