Somethng wrong with code.

Thedon123

Registered User.
Local time
Today, 17:40
Joined
Sep 11, 2002
Messages
98
Problem is that it does jump to the error function immediately, instead it carries out the import command then generates an error.

import:
'Show the Open common dialog box
CommonDialog2.ShowSave
'Return the path and file name selected or
'Return an empty string if the user cancels the dialog
SaveCFile = CommonDialog2.filename
If CommonDialog2.filename <> "" Then
CSV_Name = CommonDialog2.filename
On Error GoTo ExportC_Err t is supposed to goto the error screen below. Instead it does the command below.
' Displays message of what is going to happen
MsgBox "It may take a few minutes....Please be patient", vbInformation, "Exporting C Data"
DoCmd.OpenForm "Please Wait 2", acNormal, "", "", , acNormal


' Turn warnings off!
DoCmd.SetWarnings False
DoCmd.Hourglass True
'Finds organises and builds the necessary claims to be exported to the "Export_Stage3" Table
DoCmd.RunMacro ("Append Export Claim Table")
' Uses filename user typed in and exports it to a text file readable by import process
DoCmd.TransferText acExportFixed, "Export", "Export_Stage3", CSV_Name, False, ""

' Displays message of what is going to happen after database has compacted
DoCmd.Close acForm, "Please Wait 2"

Beep
MsgBox "Selected Claims have been Exported." & vbCrLf & "REMEMBER to IMPORT them to next time you log on...!", vbInformation, "Claim Export information"
DoCmd.Close acForm, "Submit C Results"
DoCmd.SetWarnings True
DoCmd.Hourglass False

ExportClaim_Exit:
Exit Function

ExportClaim_Err:
MsgBox "Claims Not exported....Either You cancelled the process or there is an error", vbOKOnly
DoCmd.Close acForm, "Please Wait 2"
DoCmd.Hourglass False
Resume ExportClaim_Exit


End If
 
Try this

import:
'Show the Open common dialog box
CommonDialog2.ShowSave
'Return the path and file name selected or
'Return an empty string if the user cancels the dialog
SaveCFile = CommonDialog2.filename

If CommonDialog2.filename <> "" Then
CSV_Name = CommonDialog2.filename
Else
GoTo ExportC_Err
End if

' Displays message of what is going to happen
MsgBox "It may take a few minutes....Please be patient", vbInformation, "Exporting C Data"
DoCmd.OpenForm "Please Wait 2", acNormal, "", "", , acNormal
' Turn warnings off!
DoCmd.SetWarnings False
DoCmd.Hourglass True
'Finds organises and builds the necessary claims to be exported to the "Export_Stage3" Table
DoCmd.RunMacro ("Append Export Claim Table")
' Uses filename user typed in and exports it to a text file readable by import process
DoCmd.TransferText acExportFixed, "Export", "Export_Stage3", CSV_Name, False, ""

' Displays message of what is going to happen after database has compacted
DoCmd.Close acForm, "Please Wait 2"

Beep
MsgBox "Selected Claims have been Exported." & vbCrLf & "REMEMBER to IMPORT them to next time you log on...!", vbInformation, "Claim Export information"
DoCmd.Close acForm, "Submit C Results"
DoCmd.SetWarnings True
DoCmd.Hourglass False

ExportClaim_Exit:
Exit Function

ExportClaim_Err:
MsgBox "Claims Not exported....Either You cancelled the process or there is an error", vbOKOnly
DoCmd.Close acForm, "Please Wait 2"
DoCmd.Hourglass False
Resume ExportClaim_Exit


The error code was not trapping the error probably because one was not being created. This way a string other than an empty one will continue. You may have to write something to trap non usable file names i.e. if the user puts in test.ing.doc etc

HTH
John
 
Didnt work mate still does the whole routine before falling down.
 

Users who are viewing this thread

Back
Top Bottom