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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creat directory

Status
Not open for further replies.

Biomechanoids

Programmer
Oct 18, 2002
14
US
I want to creat a direcotory with the name of the content of a certain field of an access - database. The trouble I have is that the MkDir"" method of VBA wants a String as path. I tried to do it like

outputSQL = "SELECT name FROM table1 WHERE key = 1"

MkDir "C:\"&outputSQL

...but that doesn't work. The only thing that happens is that the module creates an empty folder.

Maybe somebody can give me a hint what's going wrong?

Greetings
Thomas
 
use a DAO recordset, do some thing like this...

dim rs as DAO.Recordset

set rs = currentdb.openrecordset("SELECT name FROM table1 WHERE key = 1")

MkDir "C:\" & rs!name

rs.close
set rs = nothing

I use DAO since i don't know if your using access 2k/2k2/97...

Hope this helps...

--James junior1544@jmjpc.net
Life is change. To deny change is to deny life.
 
I'm not sure what your directory name should be. As you have it written, you are attempting to create the following directory "c:\SELECT name FROM table1 WHERE key = 1". Is this what you want the directory name to look like?
 
Yes, like that, the content of the field in the database. For example the field contains the word "example". So the name of the directory should be C:\example .
 
try out the solution i gave and see how you like it... I can help you customize it if you'd like...

--James
junior1544@jmjpc.net
Life is change. To deny change is to deny life.
 
@junior1544

Thank you for the offer and I will take it with gratitude.

I insert the code in a module, here is the complete code:

Public Sub EasyLoop()

'declaring variables
Dim conMan As ADODB.Connection
Dim rstMan As New Recordset
Dim strSQL As String
Dim outPut As String
Dim rs As ADODB.Recordset


'opening connection
Set conMan = CurrentProject.Connection
strSQL = "SELECT *FROM clients"
Set rstMan.ActiveConnection = conMan
rstMan.Open strSQL, , adOpenForwardOnly, adLockReadOnly, adCmdText


'test for creating a certain directory on the C:\


Set rs = CurrentDb.openrecordset("SELECT client FROM clients WHERE key = 1")
MkDir "C:\" & rs!client
rs.Close
Set rs = Nothing
End Sub


I changed the Databaseobject from DAO to ADODB because the other one caused an error. The Problem now is that I get an type mismatch error in the Set rs = CurrentDB.... line. Maybe you got a clue what went wrong?

Greetings

Thomas
 
CurrentDB doesn't excist is ADO... I havn't learned ado yet(another reason i didn't give it to you in ado...)

If you want to run it in dao i can help you get it working...

You would just have to make sure that you have dao referenced...

then when you get around to it you can convert it to ado...

--James
junior1544@jmjpc.net
Life is change. To deny change is to deny life.
 
glad to hear it...

I'm working on learning ado for dealing with recordsets... it's time consuming since i default to using dao all the time...

the only time i have to work with ado is when i'm reading other people's work...

thanks for the time...

--James
junior1544@jmjpc.net
Life is change. To deny change is to deny life.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top