Create Folder Named [Field1] & " " & [Field2]

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way to click a button on a form and have it combine two fields on
the form into a file name and use that file name to make a new file folder in
a designated directory? Every time I get a new physical file, I have to make
a folder on the network. Sometimes I forget, but I always enter all the file
data into my access form.

Please advise.

Thank you.
 
Beverly76 said:
Is there a way to click a button on a form and have it combine two
fields on the form into a file name and use that file name to make a
new file folder in a designated directory? Every time I get a new
physical file, I have to make a folder on the network. Sometimes I
forget, but I always enter all the file data into my access form.

Sure, though the need to do this seems rather strange. The basic code
would be something like this:

'----- start of example code -----
Private Sub cmdMakeFolder_Click()

Const conBaseFolder As String = "C:\Some Path\Some Folder\"
' this would be the folder you want to create new folders in.

Dim strNewFolder As String

strNewFolder = _
conBaseFolder & _
Me![Field1] & " " & Me![Field2]

If Len(Dir(strNewFolder, vbDirectory)) > 0 Then
MsgBox "The folder '" & strNewFolder & "' already exists!"
Else
MkDir strNewFolder
End If

End Sub
'----- end of example code -----

Note that all the folders higher up in the hierarchy must already exist
before you can create a new folder.
 
Thanks! Amazingly - this worked perfectly and immediately. This comes in
handy because one of my fields is a six digit number. By creating the file
folder automatically, it ensures that I don't mistype the number and it keeps
me from having to look it up later.
--
Sincerely,
Beverly76


Dirk Goldgar said:
Beverly76 said:
Is there a way to click a button on a form and have it combine two
fields on the form into a file name and use that file name to make a
new file folder in a designated directory? Every time I get a new
physical file, I have to make a folder on the network. Sometimes I
forget, but I always enter all the file data into my access form.

Sure, though the need to do this seems rather strange. The basic code
would be something like this:

'----- start of example code -----
Private Sub cmdMakeFolder_Click()

Const conBaseFolder As String = "C:\Some Path\Some Folder\"
' this would be the folder you want to create new folders in.

Dim strNewFolder As String

strNewFolder = _
conBaseFolder & _
Me![Field1] & " " & Me![Field2]

If Len(Dir(strNewFolder, vbDirectory)) > 0 Then
MsgBox "The folder '" & strNewFolder & "' already exists!"
Else
MkDir strNewFolder
End If

End Sub
'----- end of example code -----

Note that all the folders higher up in the hierarchy must already exist
before you can create a new folder.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
This information that you posted was very helpful to me and I have
implemented it in my database.

Now I want to take this one step further and place the address information
for the newly created (e.g. C:Folder\address\) into a text box field.

The rationale is so that the user can see the location of the folder that
has just been created.

Can you help me with this?

Thanks

Dirk Goldgar said:
Beverly76 said:
Is there a way to click a button on a form and have it combine two
fields on the form into a file name and use that file name to make a
new file folder in a designated directory? Every time I get a new
physical file, I have to make a folder on the network. Sometimes I
forget, but I always enter all the file data into my access form.

Sure, though the need to do this seems rather strange. The basic code
would be something like this:

'----- start of example code -----
Private Sub cmdMakeFolder_Click()

Const conBaseFolder As String = "C:\Some Path\Some Folder\"
' this would be the folder you want to create new folders in.

Dim strNewFolder As String

strNewFolder = _
conBaseFolder & _
Me![Field1] & " " & Me![Field2]

If Len(Dir(strNewFolder, vbDirectory)) > 0 Then
MsgBox "The folder '" & strNewFolder & "' already exists!"
Else
MkDir strNewFolder
End If

End Sub
'----- end of example code -----

Note that all the folders higher up in the hierarchy must already exist
before you can create a new folder.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
In
Ebitari said:
This information that you posted was very helpful to me and I have
implemented it in my database.

Now I want to take this one step further and place the address
information for the newly created (e.g. C:Folder\address\) into a
text box field.

The rationale is so that the user can see the location of the folder
that has just been created.

Can you help me with this?

It should be quite simple. Where before you had this:
If Len(Dir(strNewFolder, vbDirectory)) > 0 Then
MsgBox "The folder '" & strNewFolder & "' already exists!"
Else
MkDir strNewFolder
End If

.... now you'd have this:

If Len(Dir(strNewFolder, vbDirectory)) > 0 Then
MsgBox "The folder '" & strNewFolder & "' already exists!"
Else
MkDir strNewFolder
Me!txtFolderPath = strNewFolder
End If

That assumes that "txtFolderPath" is the name of the text box where you
want to display the name of the folder, and also that this code is
running on the form that contains that text box.
 
Thanks for the information - it was very helpful.

Now I want to launch the folder so that people can save files to it.

I am using the following code:

Application.FollowHyperlink "O:\EWGPP\NA-233 Task Order & Invoice Tracking\"
& "Invoice" & " " & [Invoice Number], True

This works and opens the folder, however, when I copy a file to the folder
it does not show up until I go out of the folder and go back in. It does not
seem to be opening the folder with the right settings because I can't see
files immediately when I copy them to the opened folder. Is there a way to
open a folder in a setting that automatically refreshes when a file is saved
to it?
 
In
Ebitari said:
Thanks for the information - it was very helpful.

Now I want to launch the folder so that people can save files to it.

I am using the following code:

Application.FollowHyperlink "O:\EWGPP\NA-233 Task Order & Invoice
Tracking\" & "Invoice" & " " & [Invoice Number], True

This works and opens the folder, however, when I copy a file to the
folder it does not show up until I go out of the folder and go back
in. It does not seem to be opening the folder with the right
settings because I can't see files immediately when I copy them to
the opened folder. Is there a way to open a folder in a setting that
automatically refreshes when a file is saved to it?

How are you copying the files? If you have opened the folder via
FollowHyperlink, the folder will naturally reflect the files that are in
it, and any files that are copied into it manually via the user
interface. If you're using code to copy files into the folder, I
suppose that you might need to refresh the folder, but my quick tests
with a folder on my C: drive didn't seem to have this problem. If the
folder is on a network, there my be a longer latency, though.

I have no idea how you would programmatically refresh a folder -- maybe
by locating its window via an API call and sending it a "refresh"
message of some sort. But if you'll describe what you're doing in more
detail, we may be able to come up with something.
 

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

Back
Top