473,401 Members | 2,125 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,401 software developers and data experts.

Verify file name exist from table field

Is it possible and if so, how?

Would like to have code to verify that a file name in a same directory matches with the file name in a table/ field. If it matches then run the rest of the code, if not prompt with error.

Can someone give me some pointer how this should be written

Thanks for any help you could offer
Jun 16 '10 #1

✓ answered by NeoPa

I would start with the field value in the table. The current folder can be found from CurrentProject.FullName if you remove the name part. Add the value from the field to this and use the Dir() function to determine if it does indeed exist.

Using FileSystemObject is an alternative, but I would say it's more complicated and requires a library reference which is less standard than the VBA one which is common to all projects.

4 2327
Found something that may work.

Expand|Select|Wrap|Line Numbers
  1. Dim fso
  2. Dim file As String
  3. file = strXLFile   ' change to match the file w/Path
  4. Set fso = CreateObject("Scripting.FileSystemObject")
  5. If Not fso.FileExists(file) Then
  6.     MsgBox file & " was not located.", vbInformation, "File Not Found"
  7. Else
  8.     MsgBox file & " has been located.", vbInformation, "File Found"
  9. End If
  10.  
Still open to any other suggestions
Jun 17 '10 #2
NeoPa
32,556 Expert Mod 16PB
I would start with the field value in the table. The current folder can be found from CurrentProject.FullName if you remove the name part. Add the value from the field to this and use the Dir() function to determine if it does indeed exist.

Using FileSystemObject is an alternative, but I would say it's more complicated and requires a library reference which is less standard than the VBA one which is common to all projects.
Jun 17 '10 #3
@NeoPa
Excellent Suggestion...
I am trying the following and it works

Expand|Select|Wrap|Line Numbers
  1.  
  2. If Len(Dir(strXLFile)) = 0 Then
  3.         MsgBox "Could not find " & strXLFileName & ", Check the " & strCurrentDir & " Folder and the Paths Setup to be sure the file names match.", vbInformation, "File Not Found"
  4.         GoTo Exit_Sub
  5.     Else
  6.        'Continue through the code
  7.     End If
  8.  
Jun 18 '10 #4
NeoPa
32,556 Expert Mod 16PB
Glad you got it working Tim. I'd suggest replacing line #5 (Else) with line #7 (End If), but that's just semantics.
Jun 18 '10 #5

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

Similar topics

10
by: MLH | last post by:
I have an A97 table with a Yes/No field named TowJob and a form bound to that table. The TowJob control on the form is bound to the same field. It is an option group with Yes and No bttns valued...
2
by: Greg Strong | last post by:
Hello All, Is it possible to change table field lookup properties in code? I've been able to change other field properties in code, however so far no luck with field lookup properties. What...
1
by: Gaetan | last post by:
I have a web application where the user can type the name of a file name in a field. I want to make sure the syntax of that filename is valid before using it. I browsed the methods in various...
18
by: walterbyrd | last post by:
I am trying to develop an app where: the same file, in the same place, will be uploaded, and then processed. Everything I can find about uploading a file, uses a form that requires the user to...
4
by: bryanp10 | last post by:
How do I do a client-side check to see that a file exists before attempting to upload it? I am trying to avoid the "Access denied" error I get on form submission if an invalid name is entered in...
4
by: M6C | last post by:
Hello, I'm trying to import a Xml file in a table. It's working find, but when the data are inserted, my trigger on this table doesn't work ? I put my code below. Best regards Thank's
185
by: jacob navia | last post by:
Hi We are rewriting the libc for the 64 bit version of lcc-win and we have added a new field in the FILE structure: char *FileName; fopen() will save the file name and an accessor function will...
3
by: adiel_g | last post by:
Hello everyone, I am trying to move a field name to a variable in vb.net. For example, first I retrieve the record from the database and save its value: .... userGroup =...
6
by: provor | last post by:
Hello, I have the following code that I am using when a user presses a button to import an excel file into a table. The code is hard coded to point to the correct table. This works great for this...
2
by: timleonard | last post by:
How do you reference the Table:Field to use in a file path? I have been trying the code below I would like to reference a Tablel:Field to use in the path instead of hard coding the file name,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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,...
0
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...

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.