Check Code for Weakness/Error?

crhodus

Registered User.
Local time
Today, 06:29
Joined
Mar 16, 2001
Messages
257
Can anyone briefly look over the code that I have written for any errors/potential errors. The code seems to be working correctly, but I am not that confident in my vba skills.

Brief explanation:
The form frmLastUpdated will display the last time data was exported. When the user clicks on the OK button, frmLastUpdated's visible property is set to False and function Input_Export_Date is run. The variable Input_Export_Date is a global variable.

Public Function Input_Export_Date()

On Error GoTo Err_Cancel_Exp
Const conErrCancelExp = 13

'Input_Export_Date is a global variable
Input_Export_Date = InputBox("BEGIN EXPORT OF DATA: How far do you wish to go back? (MM/DD/YY)")

'If Input_Export_Date is not null, then make frmLastUpdated visible and then close frmLastUpdated.
'The variable strExp_Date is given the value of Input_Export_Date

If Not IsNull(Input_Export_Date) Then
Forms!frmLastUpdated.Visible = True
DoCmd.Close acForm, "frmLastUpdated"
strExp_Date = Input_Export_Date
End If

'Display date range of data that is about to be exported in message box.
MsgBox "Data from " & strExp_Date & " to " & Date & " is about to be exported to the C:\ drive."

'Run macro that will export data.
DoCmd.RunMacro "Export_All_Macro"

Exit_Input_Export_Date:
Exit Function

Err_Cancel_Exp:

If Err.Number = conErrCancelExp Then
DoCmd.Close acForm, "frmLastUpdated"
MsgBox "Export of data has been canceled:"
Else
MsgBox Err.Description
DoCmd.Close acForm, "frmLastUpdated"
End If
Resume Exit_Input_Export_Date

End Function


I'm not sure if my error code is correct.
If anyone can help, I would greatly appreciate it!

[This message has been edited by crhodus (edited 06-27-2001).]
 
From memory, error 13 is a type mismatch error.
The line of code DoCmd.Close acForm, "frmLastUpdated" is repeated 3 times. Place this line under the Exit_Input_Export_Date: label. Also, you don't have to make it visible to close it.

Jon
 

Users who are viewing this thread

Back
Top Bottom