fname = Dir("C:\Bob\*.*")

B

Bob Barnes

...code snippet..
fname = Dir("C:\Bob\*.*")
If fname = "" Then MsgBox "There Are No Files On The SD Card.", , "": Exit Sub
If fname <> "" Then..
...............................end snippet...

When running..
fname = Dir("C:\Bob\*.*")

...and there is at least one file in the Folder, sometimes fname will show "".

My code includes deleting all files in that Folder after I run code to
Import the .txt files into Access. Could that be causing the fname =
""..when that occurs??

Is there any other code to 100% see a fname = ""....when it is that?

TIA - Bob
 
P

Pieter Wijnen

Don't rely on VBA
use:
Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA"
(ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA"
(ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function GetFileAttributes Lib "kernel32" Alias
"GetFileAttributesA" (ByVal lpFileName As String) As Long
Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long)
As Long

Private Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type

'File Handling
Private Const FILE_CURRENT = 1&
Private Const FILE_BEGIN = 0&
Private Const GENERIC_READ = &H80000000
Private Const GENERIC_WRITE = &H40000000
Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2
Private Const OPEN_EXISTING = 3&
Private Const FILE_FLAG_RANDOM_ACCESS = &H10000000
Private Const FILE_ATTRIBUTE_NORMAL = &H80
Private Const FILE_ATTRIBUTE_ARCHIVE = &H20
Private Const FILE_ATTRIBUTE_DIRECTORY = &H10
Private Const FILE_ATTRIBUTE_HIDDEN = &H2
Private Const FILE_ATTRIBUTE_READONLY = &H1
Private Const FILE_ATTRIBUTE_System = &H4
Private Const FILE_ATTRIBUTE_TEMPORARY = &H100
Private Const CREATE_ALWAYS = 2&


Pieter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top