|
-
Nov 15th, 2006, 01:21 AM
#1
Thread Starter
Lively Member
[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?
Last edited by ayionick; Nov 15th, 2006 at 01:39 AM.
Reason: Resolved
-
Nov 15th, 2006, 01:25 AM
#2
Re: Create Directory/Folder
One way:
On Error Resume Next
MDir "C:\Update"
On Error GoTo 0
-
Nov 15th, 2006, 01:33 AM
#3
Thread Starter
Lively Member
Re: Create Directory/Folder
 Originally Posted by randem
One way:
On Error Resume Next
MDir "C:\Update"
On Error GoTo 0
I got "Sub or Function" error message.
-
Nov 15th, 2006, 01:37 AM
#4
Thread Starter
Lively Member
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
-
Nov 15th, 2006, 01:42 AM
#5
Re: [RESOLVED] Create Directory/Folder
OK, happy fingers forgot the k
-
Nov 15th, 2006, 02:10 AM
#6
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.
-
Nov 15th, 2006, 02:20 AM
#7
Thread Starter
Lively Member
Re: [RESOLVED] Create Directory/Folder
 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?
-
Nov 15th, 2006, 02:26 AM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|