C
CES
all,
I'm trying to figure out how Access implements error handling. The function below has two possible areas where there can be an error.
First the delete table section could cause an error if the table doesn't already exist, secondly, the function should throw an error when it attempts to execute the create table cmd.Execute because the SQL statement has been remarked out.
If I add "On Error Resume Next" to the Delete Table section and the table actually does exist, the error thrown by the missing SQL statement in the create table section will not throw a error, which I would want it to do.
So my dilemma is, how do I tell the function to step over a specific section of code, but advised me of any subsequent errors.
I appreciate any help, Thanks in advance. -- CES
Public Function fnMakeTable(tableName As String, field As String) As String
Dim cmd As ADODB.Command
Dim strSQL As String
Set cmd = New ADODB.Command
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandType = adCmdText
'Deleat Table - I don't want to know about any errors
strSQL = "DROP TABLE " & tableName
cmd.CommandText = strSQL
cmd.Execute
strSQL = ""
' Create Table - I do want to know about any errors in this section
'strSQL = "CREATE TABLE " & tableName & "(" & field & ")"
cmd.CommandText = strSQL
cmd.Execute
' refresh database window
Application.RefreshDatabaseWindow
End Function
I'm trying to figure out how Access implements error handling. The function below has two possible areas where there can be an error.
First the delete table section could cause an error if the table doesn't already exist, secondly, the function should throw an error when it attempts to execute the create table cmd.Execute because the SQL statement has been remarked out.
If I add "On Error Resume Next" to the Delete Table section and the table actually does exist, the error thrown by the missing SQL statement in the create table section will not throw a error, which I would want it to do.
So my dilemma is, how do I tell the function to step over a specific section of code, but advised me of any subsequent errors.
I appreciate any help, Thanks in advance. -- CES
Public Function fnMakeTable(tableName As String, field As String) As String
Dim cmd As ADODB.Command
Dim strSQL As String
Set cmd = New ADODB.Command
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandType = adCmdText
'Deleat Table - I don't want to know about any errors
strSQL = "DROP TABLE " & tableName
cmd.CommandText = strSQL
cmd.Execute
strSQL = ""
' Create Table - I do want to know about any errors in this section
'strSQL = "CREATE TABLE " & tableName & "(" & field & ")"
cmd.CommandText = strSQL
cmd.Execute
' refresh database window
Application.RefreshDatabaseWindow
End Function