Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Question for RanjeetRain?

Posted on 2004-08-02
14
Medium Priority
?
205 Views
Last Modified: 2013-12-18
STPD question, but the code doesn't seem to work, maybe I missed something to create
   C:\WORK\ABC
Sub CreateDir(Byval DirName As String)
     Dim Parent As String
     Dim ParentExists As Variant
     
     On Error Resume Next
     Parent = Strleftback(Dirname, "\")
     ParentExists = Dir(Parent)
     
     If ParentExists = "" Then
          If Len(Parent) > 2 Then
               Msgbox "Call " + Parent
               Call CreateDir (Parent)
          End If
     End If
     Mkdir Dirname
End Sub

0
Comment
Question by:cyle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
  • 2
14 Comments
 
LVL 31

Expert Comment

by:qwaletee
ID: 11697552
Just noticed, there is no error checking!

What message boxes pop up?
0
 

Author Comment

by:cyle
ID: 11697586
None, just didn't create any.
0
 
LVL 31

Assisted Solution

by:qwaletee
qwaletee earned 400 total points
ID: 11697737
Change to


Sub CreateDir(Byval DirName As String)
     Dim Parent As String
     Dim ParentExists As Variant
     
     On Error Resume Next
     Parent = Strleftback(Dirname, "\")
     ParentExists = Dir(Parent)
     
     If ParentExists = "" Then
          If Len(Parent) > 2 Then
               Msgbox "Call " + Parent
               Call CreateDir (Parent)
          End If
     Else
          Msgbox "Not necessary to create " & parent & " - just create final"
     End If
if err <> 0 then
    msgbox "prelude error " & error,,err
    err = 0
else
     Mkdir Dirname
if err <> 0 then
    msgbox "mkdir error " & error,,err
    err = 0
end if
   
End Sub

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Expert Comment

by:RanjeetRain
ID: 11702786
Cyle,

THat is a 'TESTED OK' sub. The thing is - U also have to call it. Did you call it :)


After having typed that function.. you also have to call that SUB with an argument. Did you do that? I think you didn't :)

Call CreateDir ("C:\WORK\ABC")

Mission completed.
0
 
LVL 19

Expert Comment

by:RanjeetRain
ID: 11703071
Qwaletee,

That is some non-value-add code you added. Doesn't really help a lot. Besides, I feel your code won't even compile.
0
 

Author Comment

by:cyle
ID: 11703435
This is what I have. I had it working the first time but when I tested it (deleted the first one and tried creating it again, nothing happens)
Dim Parent As String
Dim ParentExists As Variant

On Error Resume Next
Parent = Strleftback("C:\WORK\ABC", "\")
ParentExists = Dir(Parent)

If ParentExists = "" Then
   If Len(Parent) > 2 Then
'   Msgbox "Call " + Parent
   Call CreateDir ("C:\WORK\ABC")
  End If
End If
MKdir Dirname

0
 
LVL 19

Expert Comment

by:RanjeetRain
ID: 11703579
NO, NO, NO! That will cause an INFINITE LOOP. Do this!

1. Put the sub in in a Script Library
2. Use the Script Library in your form/agent
3. Call it like
       Call CreateDir ("C:\WORK\ABC")
    from wherever you want to create the directory.

If anything is not clear, pls let me know.
0
 

Author Comment

by:cyle
ID: 11703646
I do have Sub CreateDir.....

Call createdir(doc)  --- This is how I call it.
0
 
LVL 19

Expert Comment

by:RanjeetRain
ID: 11703916
NO! Call it like

Call CreateDir ("C:\WORK\ABC")

If you have to pick the value dynamically from the document, you may call it like:

Call CreateDir (doc.path(0))
0
 

Author Comment

by:cyle
ID: 11703999
"Variant does not exist."
0
 
LVL 19

Expert Comment

by:RanjeetRain
ID: 11704233
Yes, if your form doesn't have a field called PATH. See, do you want a dynamic path? Only then you have to take it from the document. Otherwise simply use the first version:

Call CreateDir ("C:\WORK\ABC")

Thats sufficient.

0
 

Author Comment

by:cyle
ID: 11704392
Sorry Ranjeet, here it is again.
Sub CreateDir(Byval DirName As String)
  Dim Parent As String
  Dim ParentExists As Variant
  On Error Resume Next
  Parent = Strleftback("C:\WORK\RFCECN", "\")
  ParentExists = Dir(Parent)
  If ParentExists = "" Then
     If Len(Parent) > 2 Then
       Call CreateDir ("C:\WORK\RFCECN")
     End If
  End If
Mkdir Dirname
End Sub

Call CreateDir ("C:\WORK\RFCECN")  Calling it as this.

wordobj.filesaveas "C:\WORK\RFCECN\" & RFC & ".doc"  , , , , , ,True, , , , , True     Saving it as this.

I get the error in saving, it would asks me to check the filepath. I also checked my C: and no C:\WORK is even created.

0
 
LVL 19

Accepted Solution

by:
RanjeetRain earned 1600 total points
ID: 11704705
Oh oh. The same mistake again. YOu couldn't understand the context. You do not have to modify the call to CreateDir at all places. Only at one place. In your sub declaration you do not have to hard-code the path. DO NOT modify the sub declaration. Copy paste this one.


Sub CreateDir(Byval DirName As String)
    Dim Parent As String
    Dim ParentExists As Variant
   
     On Error Resume Next
    Parent = Strleftback(Dirname, "\")
    ParentExists = Dir(Parent)
   
     If ParentExists = "" Then
          If Len(Parent) > 2 Then
              Msgbox "Call " + Parent
              CreateDir Parent
         End If
    End If
    Mkdir Dirname
End Sub



Call CreateDir ("C:\WORK\RFCECN")  


NOTICE that I have only modified the main call to the sub... and not the Sub definition itself :)
0
 

Author Comment

by:cyle
ID: 11705308
Thanks!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
Problem "Can you help me recover my changes?  I double-clicked the attachment, made changes, and then hit Save before closing it.  But when I try to re-open it, my changes are missing!"    Solution This solution opens the Outlook Secure Temp Fold…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question