PC Review


Reply
Thread Tools Rate Thread

Delete Table Function Not Working

 
 
=?Utf-8?B?dnNlYWxl?=
Guest
Posts: n/a
 
      21st Apr 2006
I'm having a problem with the following function. The data is written to a
temp table, formatted and then exported to Excel. The function is supposed
to look for the temp table first and delete it if found. Sometimes it does,
sometimes it doesn't. Stepping through it, the IF line appears to see the
table (True=True), but sometimes it jumps to the "end if" line. This is
frustrating. Where did I go wrong?

Public Function fDeleteTempTable(strTableName As String)
On Error GoTo HandleErr

Dim lngTblCount As Long
Dim lngTblNdx As Long
Dim tdfs As TableDefs

Set tdfs = CurrentDb.TableDefs

If (IsObject(tdfs(strTableName))) = True Then
DoCmd.DeleteObject acTable, strTableName
End If


ExitHere:
Set tdfs = Nothing
Exit Function

HandleErr:
If Err.Number = "7874" Then
Resume ExitHere
ElseIf Err.Number = "3265" Then
Resume ExitHere
Else
MsgBox "Err#" & Err.Number & ": " & Err.Description
Resume ExitHere
End If

End Function


Thanks
 
Reply With Quote
 
 
 
 
=?Utf-8?B?S2xhdHV1?=
Guest
Posts: n/a
 
      21st Apr 2006
You should read the VB Help info on the IsObject function. It appears you
are not using it the way it is described and may be getting unreliable
results.

I would suggest you add this function to a standard module and use it instead.

Public Function TableExists(strTableName As String) As Boolean
Dim tdfs As TableDefs
Dim tdf As TableDef
Set tdfs = CurrentDb.TableDefs
For Each tdf In tdfs
If tdf.Name = strTableName Then
TableExists = True
Exit For
End If
Next tdf
Set tdf = Nothing
Set tdfs = Nothing

End Function



"vseale" wrote:

> I'm having a problem with the following function. The data is written to a
> temp table, formatted and then exported to Excel. The function is supposed
> to look for the temp table first and delete it if found. Sometimes it does,
> sometimes it doesn't. Stepping through it, the IF line appears to see the
> table (True=True), but sometimes it jumps to the "end if" line. This is
> frustrating. Where did I go wrong?
>
> Public Function fDeleteTempTable(strTableName As String)
> On Error GoTo HandleErr
>
> Dim lngTblCount As Long
> Dim lngTblNdx As Long
> Dim tdfs As TableDefs
>
> Set tdfs = CurrentDb.TableDefs
>
> If (IsObject(tdfs(strTableName))) = True Then
> DoCmd.DeleteObject acTable, strTableName
> End If
>
>
> ExitHere:
> Set tdfs = Nothing
> Exit Function
>
> HandleErr:
> If Err.Number = "7874" Then
> Resume ExitHere
> ElseIf Err.Number = "3265" Then
> Resume ExitHere
> Else
> MsgBox "Err#" & Err.Number & ": " & Err.Description
> Resume ExitHere
> End If
>
> End Function
>
>
> Thanks

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Outlook Express 6 DELETE function not working Papa Doc Microsoft Outlook Discussion 1 13th Feb 2008 02:56 AM
I have a CLR function thet returns IEnumberable (a table) and it has a FillRow function. I am returning 10,000 integers from this function. Is there any way that I can preallocate the resulting table or give SQL server hint as to how many rows my fun DR Microsoft Dot NET Framework 1 22nd Nov 2007 11:36 AM
Why has the delete function stopped working with selected text? =?Utf-8?B?Sm9l?= Microsoft Word Document Management 2 28th Jun 2005 05:01 PM
Control-Alt-Delete function stopped working =?Utf-8?B?TVRDYXRjaA==?= Windows XP General 4 18th May 2005 06:11 AM
The delete function is not working in outlook xp (delete is 'grey. =?Utf-8?B?ZWhhdXNlcg==?= Microsoft Outlook Discussion 0 6th Apr 2005 05:17 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:08 PM.