Results 1 to 8 of 8

Thread: [RESOLVED] Create Directory/Folder

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2006
    Posts
    81

    Resolved [RESOLVED] Create Directory/Folder

    Here's my form code:
    VB Code:
    1. Private Sub cmdUpdate_Click()
    2.  
    3. On Error GoTo errorHandler:
    4.  
    5.         Call fileOutput(Me, 0)
    6.         x = MsgBox("Record updated.", vbInformation + vbOKOnly, "Update")
    7.         Call mdlMain.clear(Me)
    8.         dtpDateFrom.SetFocus
    9.  
    10. errorHandler:
    11.     FileErrors

    module code(fileOutput function):
    VB Code:
    1. dfrom = frmref.dtpDateFrom.Value
    2.         dto = frmref.dtpDateTo.Value
    3.         addOne = Format(DateAdd("d", 1, dto), "YYYYMMDD")
    4.        
    5.         'copy textfile content to another texfile
    6.         Open "C:\Upload\NewClient.txt" For Input As #1
    7.         Do While Not EOF(1)
    8.             Line Input #1, sLines
    9.                 mydate = Left(sLines, 12)
    10.                 If Format(dfrom, "YYYYMMDD") <= mydate And mydate < addOne Then
    11.                     Output = Output & vbCrLf & sLines
    12.                 End If
    13.         DoEvents
    14.         Loop
    15.         Close #1
    16.        
    17.         'write in textfile
    18.         Open "c:\Update\NewClient.txt" For Output As #1
    19.         Print #1, Output
    20.         Close #1

    error trapping:
    VB Code:
    1. Public Const mnErrPathDoesNotExist = 76
    2.  
    3. Public Function FileErrors() As Integer
    4.     Select Case Err.Number
    5.         Case mnErrPathDoesNotExist              ' Error 76
    6.             strMsg = "The path or file you are trying to access doesn't exist."
    7.             strMsg = strMsg & vbCrLf & "It maybe renamed, moved or deleted."
    8.             strMsg = strMsg & vbCrLf & "Please contact your administrator."
    9.             intMsgType = vbExclamation + vbOKOnly


    These codes are running already. When I don't call errorHandler/fileError, the VB6 program automatically create "C:\Update". But when there's error trapping mnErrPathDoesNotExist appears.

    How will I create "C:\Update" even with error trapping?
    Last edited by ayionick; Nov 15th, 2006 at 01:39 AM. Reason: Resolved

  2. #2
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Create Directory/Folder

    One way:

    On Error Resume Next
    MDir "C:\Update"
    On Error GoTo 0

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2006
    Posts
    81

    Re: Create Directory/Folder

    Quote Originally Posted by randem
    One way:

    On Error Resume Next
    MDir "C:\Update"
    On Error GoTo 0
    I got "Sub or Function" error message.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Oct 2006
    Posts
    81

    Re: Create Directory/Folder

    Thanks randem, got it right already!

    It should be:

    VB Code:
    1. On Error Resume Next
    2. MkDir "C:\Update"
    3. On Error GoTo 0

  5. #5
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: [RESOLVED] Create Directory/Folder

    OK, happy fingers forgot the k

  6. #6
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: [RESOLVED] Create Directory/Folder

    you need to add Exit Sub just before the Error Handler
    Code:
    Private Sub cmdUpdate_Click()
    
    On Error GoTo errorHandler:
    
            Call fileOutput(Me, 0)
            x = MsgBox("Record updated.", vbInformation + vbOKOnly, "Update")
            Call mdlMain.clear(Me)
            dtpDateFrom.SetFocus
            Exit Sub 'NEED TO ADD THIS LINE
    errorHandler:
        FileErrors
    End Sub
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  7. #7

    Thread Starter
    Lively Member
    Join Date
    Oct 2006
    Posts
    81

    Re: [RESOLVED] Create Directory/Folder

    Quote Originally Posted by ganeshmoorthy
    you need to add Exit Sub just before the Error Handler
    Code:
    Private Sub cmdUpdate_Click()
    
    On Error GoTo errorHandler:
    
            Call fileOutput(Me, 0)
            x = MsgBox("Record updated.", vbInformation + vbOKOnly, "Update")
            Call mdlMain.clear(Me)
            dtpDateFrom.SetFocus
            Exit Sub 'NEED TO ADD THIS LINE
    errorHandler:
        FileErrors
    End Sub
    This code is actually inside a loop, do I still need to put exit sub?

  8. #8
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: [RESOLVED] Create Directory/Folder

    where is the loop...are you calling the cmdUpdate_click from a loop, eventhough it should have the exit sub before the error handler...the syntax of a proc/sub should be
    Code:
    Private Sub ProcName ()
        On Error GoTo ErrHandler
        'your codings
        Exit Sub
    ErrHandler:
        'Code to handle errors
    Exit Sub
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width