Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating Folder per Record 1

Status
Not open for further replies.

ckugo

IS-IT--Management
Jan 6, 2004
165
US
I have a database with tons of data in it. I need to create a folder for certain records named their id and name (exp. Name 33312346). Each record that needs a folder created will begin with the same prefix for their id. I know how to create a folder with vb scipt, but I am not having any luck with vba code. So I basically need to scan my database and create a folder in a certain directory for every record that begins with 333 named "Name 333123456." If anyone has any advice on this I would really apreciate it.

Thanks for your time,

Chris
 
Code should look something like this. I haven't tested this exact variation, but it should be darn close.

Code:
Sub MakeFolders()
Dim rs as New AdoDb.Recordset
Dim strPath as String

strPath = "C:\WINDOWS\"
rs.Open "SELECT * FROM tblNameHere WHERE Left([Field],3)=333

Do While Not rs.EOF
  MkDir strPath & rs!Name & "_" & rs!Id
  rs.MoveNext
Loop

End Sub


I am what I am based on the decisions I have made.

DoubleD [bigcheeks]
 
Thank you so much for the code. I am pretty sure that it is exactly what I need. When I try to run it though, I get a compiler error though.

On:

Dim rs as New Adodb.Recordset

Compile error:
User-defined type not defined.


Once again thank you and all the help that you give is greatly appreciated.

Thanks,

Chris
 
You have to have a reference to ADO.
Check under Tools...Reference
Make sure you have a Microsoft ActiveX Data Objects Library checked.

I am what I am based on the decisions I have made.

DoubleD [bigcheeks]
 
Thanks againm, that solved that issue, now I am getting another error.

Run-Time erroe: 3709

The connection cannot be used to perform this operation. It is either closed or invalid in this context.

It is referencing the rs.open line.

Any ideas on what is causing this??

Thanks so much,

Chris
 
rs.Open "SELECT * FROM tblNameHere WHERE Left([Field],3)= '333'", CurrentProject.Connection

Sorry, this line should fix it.

I am what I am based on the decisions I have made.

DoubleD [bigcheeks]
 
Thank you so much. Works like a charm. Have a star!


Thanks,

Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top