VBA Code for Access Command Button to Create a New File Folder

Derek280zx

New Member
Joined
Feb 13, 2013
Messages
1
I have an Access Data base with a given form that creates a new recorded with the Prime Key called (MDR#). I want to add a command button to the bottom of the form so when they click on it, it will create a folder in a given location (On the network) with the folder labeled with the "MDR# (MDR# from table)".

I also would like for it to look and verify that there is not already a folder with that MDR#.

Also if possible I would like to create another command button on a given form that will open the folder dedicated to that MDR#.

Is any of this possible?

Can someone help me with the coding. I am new with access and VBA.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hi Derek,

This is definitely possible. I am assuming that you know how to put VBA behind the command buttons.

First, to make a folder given that one does not exist, I'd do something like this (please note that I am assuming that you will concatenate a path with your MDR# - make sure you add the slash between the existing path and the new - or existing - folder):

Code:
If Dir(strSomePath & <*MDR# - you need to do this part *>, vbDirectory) > vbNullString Then
    ' do nothing
Else
    MkDir strSomePath & <*MDR#*>
End If

(you could also encapsulate that into its own subroutine)

To open the folder from a command button, you might do something like this:

Code:
Shell strSomePath & <*MDR#*>, vbNormalFocus

Happy coding,
 
Upvote 0

Forum statistics

Threads
1,215,640
Messages
6,125,972
Members
449,276
Latest member
surendra75

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top