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

How to point to a specific Windows location in code?

sueb
379 256MB
We just moved our database to a more secure volume, and everything is great except for one thing: I have a button on a form that opens a specific folder based on the record in hand. The path is pretty simple (it used to be "V:\Pre-Admitting\eCharts\"), and it worked like a charm. The new location is "V:\IUR\eCharts", but when I replaced the string in my code, I get a "Path not found" error.

I can't figure out what's wrong, since the permissions are correct (I can navigate to the path outside of the database), and the path does actually exist, and it worked great with the old address.

Here's the code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Open_eChart_Click()
  2. On Error GoTo Err_Open_eChart_Click
  3.  
  4.     Dim retVal As Variant
  5.     Dim strPartialPath As String
  6.     Dim intCounter As Integer
  7.     Dim strThisChar As String
  8.     Const conPAth As String = "V:\IUR\eCharts\"
  9.  
  10.     If Not IsNull(Me![ChartNum]) Then
  11.       If Left$(Me![ChartNum], 1) = "\" Then
  12.         strPartialPath = Mid$(Me![ChartNum], 2)
  13.       Else
  14.         strPartialPath = Me![ChartNum]
  15.       End If
  16.     Else
  17.       Exit Sub
  18.     End If
  19.  
  20.     'Replace any commas with underscores
  21.     For intCounter = 1 To Len(strPartialPath)
  22.         strThisChar = Mid(strPartialPath, intCounter, 1)
  23.         If strThisChar = "," Then
  24.            strPartialPath = Left(strPartialPath, intCounter - 1) & _
  25.                 "_" & _
  26.                 Mid(strPartialPath, intCounter + 1, 255)
  27.         End If
  28.     Next
  29.  
  30.     If Dir$(conPAth & strPartialPath, vbDirectory) <> "" Then
  31.       retVal = Shell("Explorer.exe " & conPAth & strPartialPath, vbNormalFocus)
  32.     Else
  33.       MkDir (conPAth & strPartialPath)
  34.       retVal = Shell("Explorer.exe " & conPAth & strPartialPath, vbNormalFocus)
  35.     End If
  36.  
  37. Exit_Open_eChart_Click:
  38.    Exit Sub
  39.  
  40. Err_Open_eChart_Click:
  41.     MsgBox Err.Description
  42.     Resume Exit_Open_eChart_Click
  43.  
  44. End Sub
  45.  
Any help will be greatly appreciated!
Jan 20 '11 #1

✓ answered by ADezii

Not sure about the PATH Error, but I do believe that your Code can be simplified and made more efficient:
Expand|Select|Wrap|Line Numbers
  1. Dim retVal As Variant
  2. Dim strPartialPath As String
  3. Const conPAth As String = "V:\IUR\eCharts\"
  4.  
  5. If IsNull(Me![ChartNum]) Then Exit Sub
  6.  
  7. strPartialPath = Replace(Replace(Me![ChartNum], "\", ""), ",", "_")
  8.  
  9. If Dir$(conPAth & strPartialPath, vbDirectory) = "" Then MkDir (conPAth & strPartialPath)
  10.  
  11. retVal = Shell("Explorer.exe " & conPAth & strPartialPath, vbNormalFocus)

3 1480
ADezii
8,834 Expert 8TB
Not sure about the PATH Error, but I do believe that your Code can be simplified and made more efficient:
Expand|Select|Wrap|Line Numbers
  1. Dim retVal As Variant
  2. Dim strPartialPath As String
  3. Const conPAth As String = "V:\IUR\eCharts\"
  4.  
  5. If IsNull(Me![ChartNum]) Then Exit Sub
  6.  
  7. strPartialPath = Replace(Replace(Me![ChartNum], "\", ""), ",", "_")
  8.  
  9. If Dir$(conPAth & strPartialPath, vbDirectory) = "" Then MkDir (conPAth & strPartialPath)
  10.  
  11. retVal = Shell("Explorer.exe " & conPAth & strPartialPath, vbNormalFocus)
Jan 20 '11 #2
sueb
379 256MB
This IS nicer, thanks!

It turns out that the "path not found" is a function of how the new location was set up, so IT is fixing that. But I'm really glad I asked, since it garnered me this nice code simplification. :)
Jan 20 '11 #3
NeoPa
32,556 Expert Mod 16PB
With just a quick glance I can only say that the formats of the old and new folder strings are different - the newer one being without a closing "\".

Good code in this area should handle that by using something like :
Expand|Select|Wrap|Line Numbers
  1. FullPath = PathString & "\" & FileName
  2. FullPath = Replace(FullPath, "\\", "\")
That way such oversights don't cause issues.

I expect ADezii's code does something on similar lines.
Jan 21 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: learningGuy | last post by:
Can someone tell me what is wrong with this simple code? I get an exception every time at the myFile.Open() line. I have included the code that I think is needed to for you to answer this below:...
1
by: Christopher | last post by:
One of our ASP.NET Pages is starting a new Process using the Process object. When the process starts, it is started under the ASPNET User. We tried editing the web.config file and the...
4
by: bbcrock | last post by:
I have some modular code that is written for display purposes. It contains inline CSS code. I originally thought about moving all the inline code to a css file for use throughout the site- one...
4
by: Nalaka | last post by:
Hi, I have some request specific data that gets created in a "early event", that I need to pass around to many other events. I need access to this data during that request. (and more importantly...
3
by: Cleo | last post by:
How would I hard code a certain variable to be stored in a specific memory location in a processor. When I declare a variable in my program, the linker automatically determines a location and assigns...
2
by: Screaming Eagles 101 | last post by:
Hi, I found out that the Windows Generated Code is now in a new file myform.designer.vb , Through Add File I couldn't add the code to the project to see it, I had to go through Explorer and...
6
by: mcnews | last post by:
How can I direct Response.Write to output to a specific location on my page? TIA, mcnewsxp
7
by: Lior | last post by:
Hi, I have small code, that compiles on Visual C++ into a shared library (DLL). I need to compile it under linux, but the code includes some data types I'm not familiar with, such as DWORD,...
4
by: =?Utf-8?B?QXZhRGV2?= | last post by:
ASP.Net 2. We are migrating to Windows 2008 64 bit Server with IIS 7 from Windows 2003 32 Bit with IIS 6. A few library classes we wrote uses impersonation in code like explained in this...
2
by: lacole | last post by:
I have an .exe program written in C# that will not run on a specific PC that has Windows XP on it. That same .exe program will run on other Windows XP PCs though. So it's something specific to that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.