[RESOLVED] Create Directory/Folder
Here's my form code:
VB 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
errorHandler:
FileErrors
module code(fileOutput function):
VB Code:
dfrom = frmref.dtpDateFrom.Value
dto = frmref.dtpDateTo.Value
addOne = Format(DateAdd("d", 1, dto), "YYYYMMDD")
'copy textfile content to another texfile
Open "C:\Upload\NewClient.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, sLines
mydate = Left(sLines, 12)
If Format(dfrom, "YYYYMMDD") <= mydate And mydate < addOne Then
Output = Output & vbCrLf & sLines
End If
DoEvents
Loop
Close #1
'write in textfile
Open "c:\Update\NewClient.txt" For Output As #1
Print #1, Output
Close #1
error trapping:
VB Code:
Public Const mnErrPathDoesNotExist = 76
Public Function FileErrors() As Integer
Select Case Err.Number
Case mnErrPathDoesNotExist ' Error 76
strMsg = "The path or file you are trying to access doesn't exist."
strMsg = strMsg & vbCrLf & "It maybe renamed, moved or deleted."
strMsg = strMsg & vbCrLf & "Please contact your administrator."
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?
Re: Create Directory/Folder
One way:
On Error Resume Next
MDir "C:\Update"
On Error GoTo 0
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.
Re: Create Directory/Folder
Thanks randem, got it right already!
It should be:
VB Code:
On Error Resume Next
MkDir "C:\Update"
On Error GoTo 0
Re: [RESOLVED] Create Directory/Folder
OK, happy fingers forgot the k
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
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?
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