Manipulating a folder

  • Thread starter oykeong via AccessMonster.com
  • Start date
O

oykeong via AccessMonster.com

My MS Access Database pulls pictures from another folder (lets call it
PicFolder) in a different directory. I would like to put a command button in
a form (lets call it RegisrationForm) that will do the following:

1. Connect to PicFolder and search for a file whose name begins with CamSnap#.

2. If the CamSnap filename exists, change the name to one specified in a
textbox contained in RegistrationForm.

Hope someone could help me out. Thank you very much.
 
J

Jack Leach

1. Connect to PicFolder and search for a file whose name begins with
CamSnap#.

Use the Dir() function to return filenames under your critieria. Something
command like below put inside a loop...

Dir("C:\PicFolder\CamSnap*.*")

that should print the name of files it finds.

Then you can use the FileCopy function to copy the file with a new name, and
Kill function to delete the old file. I believe the Name() function will
rename a file, but I've never used it (I prefer to Copy, verify the copy, and
then delete the original).

Anyway, these functions should give you some ground to work from. THere's
tons of examples out there how to use Dir(), the rest should be pretty
straightforward. Post back if you need further help after getting a handle
on this.

hth

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
K

Klatuu

Const conFindName As String = "C:\PicFolder\Camsnap*.*"
Dim strNewName As String
Dim strFoundName As String

strFoundName = Dir(conFindName)
If strFoundName <> vbNullString Then
Name strFoundName As Me.MyTextBox
End If
 
O

oykeong via AccessMonster.com

Hi Klatuu,

Thanks a million for your response and help. I really appreciate it. I have
adapted your codes to my situation but it does not work. When I clicked the
command button, prompt showing Error 53 popped up.

I tested for the existence of the to-be-changed name file in the Immediate
window and the file name appeared which clearly shows that the file did exist.


I was thinking whether the problem could lie in the Me.MyTextBox?

Thanks again.
Const conFindName As String = "C:\PicFolder\Camsnap*.*"
Dim strNewName As String
Dim strFoundName As String

strFoundName = Dir(conFindName)
If strFoundName <> vbNullString Then
Name strFoundName As Me.MyTextBox
End If
My MS Access Database pulls pictures from another folder (lets call it
PicFolder) in a different directory. I would like to put a command button
[quoted text clipped - 8 lines]
Hope someone could help me out. Thank you very much.
 
K

Klatuu

Can you please post the code as you have it now?
Error 53 means it is not finding a file, but exactly where in the code is
the error happening?

oykeong via AccessMonster.com said:
Hi Klatuu,

Thanks a million for your response and help. I really appreciate it. I
have
adapted your codes to my situation but it does not work. When I clicked
the
command button, prompt showing Error 53 popped up.

I tested for the existence of the to-be-changed name file in the Immediate
window and the file name appeared which clearly shows that the file did
exist.


I was thinking whether the problem could lie in the Me.MyTextBox?

Thanks again.
Const conFindName As String = "C:\PicFolder\Camsnap*.*"
Dim strNewName As String
Dim strFoundName As String

strFoundName = Dir(conFindName)
If strFoundName <> vbNullString Then
Name strFoundName As Me.MyTextBox
End If
My MS Access Database pulls pictures from another folder (lets call it
PicFolder) in a different directory. I would like to put a command
button
[quoted text clipped - 8 lines]
Hope someone could help me out. Thank you very much.
 
O

oykeong via AccessMonster.com

Hi Klatuu,

Thanks for your patience in replying me again. I have found out the solution
to my problem. I just add the path to Me.MyTextBox as follows: "C:\PicFolder\
" & Me.MyTextBox. It works. But I am facing another problem.

The codes cannot differentiate between, e.g. David Copperfield and
DavidCopperfield2. When I changed the filename in C:\PicFolder from David
Copperfield to David Copperfield2, the code, If strFoundName <> vbNullString,
says that the filename exists. Why is that so?

Thanks again.

Can you please post the code as you have it now?
Error 53 means it is not finding a file, but exactly where in the code is
the error happening?
Hi Klatuu,
[quoted text clipped - 27 lines]
 
O

oykeong via AccessMonster.com

Sorry, the change in filename is from David Copperfield to David Copperfield2,
not DavidCopperfield2. Thanks
Hi Klatuu,

Thanks for your patience in replying me again. I have found out the solution
to my problem. I just add the path to Me.MyTextBox as follows: "C:\PicFolder\
" & Me.MyTextBox. It works. But I am facing another problem.

The codes cannot differentiate between, e.g. David Copperfield and
DavidCopperfield2. When I changed the filename in C:\PicFolder from David
Copperfield to David Copperfield2, the code, If strFoundName <> vbNullString,
says that the filename exists. Why is that so?

Thanks again.
Can you please post the code as you have it now?
Error 53 means it is not finding a file, but exactly where in the code is
[quoted text clipped - 5 lines]
 

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