473,472 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problem locating file using Dir() function and path using UNC (Universal Naming Conventions) in Access 2003

I have an Access 2003 application that I recently converted from
Access 97. I have a routine in which I use to export the data that
the users have keyed into a text file. This text file resides on a
network drive where the back end database resides so that multiple
users can write to the same file. I have set up the path to the back
end (under the Link Manager) using the UNC (univ. naming convention).
When this export routine runs, I need to check to see if the file
exists or not (so I can either append the data or create a new text
file with this data)

The previous version I was able to use the function
Application.Filesearch to locate the file without a problem. However,
I switched to using the Dir() command (because Filesearch did not work
in 2003) to locate the file, but I get an error "Error Number 52: Bad
File Name or Number" when I use the Dir command to locate a file that
is defined with the UNC (i.e. \\agrhq01\data1\...\pest\paa200.74)

I can map the actual path in the link manager, but preferred using the
universal name if possible.

Thanks in advance!

Stuart

The code follows:
------------------------------------------------------------------------------------------
'if output file is found, append data from the three text files to the
'end of the current file. "/b" is added as a command line option to
'prevent EOF character from being copied to the file

If dir(paafile) <"" Then

cmdmsg = Environ$("ComSpec") & " /c " & _
"copy " & paafile & "+" & _
card1file & "+" & card2file & "+" & card3file & _
" " & paafile & " /b"

ExecCmd cmdmsg

'Output file is not found, so Concatenate the 3 text files into one
file
Else
cmdmsg = Environ$("ComSpec") & " /c " & _
"copy " & card1file & "+" & _
card2file & "+" & card3file & " " & _
paafile & " /b"

ExecCmd cmdmsg

End If

Public Sub ExecCmd(cmdline$)

Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim ReturnValue As Integer

' Initialize the STARTUPINFO structure:
start.cb = Len(start)

' Start the shelled application:
ReturnValue = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)

' Wait for the shelled application to finish:
Do
ReturnValue = WaitForSingleObject(proc.hProcess, 0)
DoEvents
Loop Until ReturnValue <258

ReturnValue = CloseHandle(proc.hProcess)
End Sub

Mar 15 '07 #1
1 5875
The UNC should work find with Dir().

There may be an issue with using non-registered file types. See if it makes
any difference if you use the name paa200.txt instead of 200.74 for the
file. It does for some operations (such as TransferText.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

<st***********@ncmail.netwrote in message
news:11**********************@y80g2000hsf.googlegr oups.com...
>I have an Access 2003 application that I recently converted from
Access 97. I have a routine in which I use to export the data that
the users have keyed into a text file. This text file resides on a
network drive where the back end database resides so that multiple
users can write to the same file. I have set up the path to the back
end (under the Link Manager) using the UNC (univ. naming convention).
When this export routine runs, I need to check to see if the file
exists or not (so I can either append the data or create a new text
file with this data)

The previous version I was able to use the function
Application.Filesearch to locate the file without a problem. However,
I switched to using the Dir() command (because Filesearch did not work
in 2003) to locate the file, but I get an error "Error Number 52: Bad
File Name or Number" when I use the Dir command to locate a file that
is defined with the UNC (i.e. \\agrhq01\data1\...\pest\paa200.74)

I can map the actual path in the link manager, but preferred using the
universal name if possible.

Thanks in advance!

Stuart

The code follows:
------------------------------------------------------------------------------------------
'if output file is found, append data from the three text files to the
'end of the current file. "/b" is added as a command line option to
'prevent EOF character from being copied to the file

If dir(paafile) <"" Then

cmdmsg = Environ$("ComSpec") & " /c " & _
"copy " & paafile & "+" & _
card1file & "+" & card2file & "+" & card3file & _
" " & paafile & " /b"

ExecCmd cmdmsg

'Output file is not found, so Concatenate the 3 text files into one
file
Else
cmdmsg = Environ$("ComSpec") & " /c " & _
"copy " & card1file & "+" & _
card2file & "+" & card3file & " " & _
paafile & " /b"

ExecCmd cmdmsg

End If

Public Sub ExecCmd(cmdline$)

Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim ReturnValue As Integer

' Initialize the STARTUPINFO structure:
start.cb = Len(start)

' Start the shelled application:
ReturnValue = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)

' Wait for the shelled application to finish:
Do
ReturnValue = WaitForSingleObject(proc.hProcess, 0)
DoEvents
Loop Until ReturnValue <258

ReturnValue = CloseHandle(proc.hProcess)
End Sub
Mar 15 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: hokiegal99 | last post by:
A few questions about the following code. How would I "wrap" this in a function, and do I need to? Also, how can I make the code smart enough to realize that when a file has 2 or more bad...
5
by: matt dittman | last post by:
I have created a windows service that reads emails from a drop directory and moves them to the appropriate mail folder every 15 seconds. I can move, rename and delete the files as needed, up...
1
by: sparks | last post by:
I have never done this and wanted to ask people who have what is the best way. One person said import it to excel, then import it into access table. but since this will be done a lot, I am...
1
by: Dennis Gaida | last post by:
Hi there, I want to upload some exported reports to a FTP Server, for this I use a command line FTP utility. My Database sits in C:\Documents and Settings\Dennis\My Documents\Database The FTP...
2
by: Joseph Geretz | last post by:
I'm having a credentialing problem in my web application. Actually, I don't think this is an IIS security issue, since I'm able to access the page I'm requesting. However, the executing page itself...
5
by: Nathan Sokalski | last post by:
I am trying to write code to allow my users to upload a file. The code I am using is as follows: Dim upfilename As String = "" If fileDetails.Value <> "" AndAlso...
5
by: Segfahlt | last post by:
I need a little help here please. I have 2 win forms user controls in 2 different projects that I'm hosting in 2 different virtual directories. The controls have been test and operate okay in...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
6
by: Gaijinco | last post by:
I'm trying to do a template class Node. My node.hpp is: #ifndef _NODE_HPP_ #define _NODE_HPP_ namespace com { namespace mnya { namespace carlos { template <typename T>
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...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.