Check if a table exist doesn't work 
Author Message
 Check if a table exist doesn't work

HELP!!
this generates a error were i do not get rid of it
what are i am doing wrong

it gives the error item not find in this collection (what is true ofcourse)
but error handeling does not react on this :(

i need to check if a table exist ( if not i want to make it if it is i need
to append fields to it)

thanx

Function DoesTableExist(sTblName As String) As Boolean
   Dim dbs As dao.Database
   Dim tbldef As dao.TableDef
   Dim rst As Recordset
   Dim x

On Error GoTo DoesTableExist_err
   Set dbs = OpenDatabase("C:\WindowsUren\NoordWind.mdb")

    Set tbldef = dbs.TableDefs(sTblName)
       x = dbs.TableDefs(sTblName).Fields.Count
   DoesTableExist = True

DoesTableExist_end:
    Exit Function

DoesTableExist_err:
    MsgBox Err.Number
    DoesTableExist = False
    resume     DoesTableExist_end
End Function



Thu, 12 Dec 2002 03:00:00 GMT  
 Check if a table exist doesn't work
I'm not clearon how the function is behaving. It should err out and return
FALSE if the table does not exist.
I don't understand the purpose of setting variable x equal to count of
fields collection.

I would suggest that a more straightforward "table exists" test function
might loop through the tables collection, returning TRUE if a match is
found:

Public Function TableExists(strDbPath as String, strTablename as String) as
Boolean
on error goto TableExists_Err

    dim db as DAO.database
    dim tdf as DAO.tabledef

'initialize return value
TableExists = FALSE

Set db = OpenDatabase(strDbPath)

For Each tdf in db.Tabledefs
    If tdf.name = strTableName
        TableExists = TRUE
        Exit For
    End if
Next tdf

TableExists_Exit:
on error resume next
Exit Function

TableExists_Err:
msgbox "TableExists" & vbcrlf & _
err.number & vbcrlf & err.description
Resume TableExists_Exit
End Function


Quote:
> HELP!!
> this generates a error were i do not get rid of it
> what are i am doing wrong

> it gives the error item not find in this collection (what is true
ofcourse)
> but error handeling does not react on this :(

> i need to check if a table exist ( if not i want to make it if it is i
need
> to append fields to it)

> thanx

> Function DoesTableExist(sTblName As String) As Boolean
>    Dim dbs As dao.Database
>    Dim tbldef As dao.TableDef
>    Dim rst As Recordset
>    Dim x

> On Error GoTo DoesTableExist_err
>    Set dbs = OpenDatabase("C:\WindowsUren\NoordWind.mdb")

>     Set tbldef = dbs.TableDefs(sTblName)
>        x = dbs.TableDefs(sTblName).Fields.Count
>    DoesTableExist = True

> DoesTableExist_end:
>     Exit Function

> DoesTableExist_err:
>     MsgBox Err.Number
>     DoesTableExist = False
>     resume     DoesTableExist_end
> End Function



Thu, 12 Dec 2002 03:00:00 GMT  
 Check if a table exist doesn't work
On Sun, 25 Jun 2000 13:19:21 +0200, "Jos Groen"

comp.lang.basic.visual.database:

Quote:
>HELP!!
<snip>

>Function DoesTableExist(sTblName As String) As Boolean
>   Dim dbs As dao.Database
>   Dim tbldef As dao.TableDef
>   Dim rst As Recordset
>   Dim x

>On Error GoTo DoesTableExist_err
>   Set dbs = OpenDatabase("C:\WindowsUren\NoordWind.mdb")

     For Each tbldef in dbs.TableDefs
          If UCase(tbldef.Name) = UCase(sTblName) Then
               DoesTableExist = True
               Exit For
          End If
     Next

<snip>

Try the above code



Thu, 12 Dec 2002 03:00:00 GMT  
 Check if a table exist doesn't work
thanx
this works fine
it indead the right way
better to do it this way

Larry Calame heeft geschreven in bericht

Quote:
>I'm not clearon how the function is behaving. It should err out and return
>FALSE if the table does not exist.
>I don't understand the purpose of setting variable x equal to count of
>fields collection.

>I would suggest that a more straightforward "table exists" test function
>might loop through the tables collection, returning TRUE if a match is
>found:

>Public Function TableExists(strDbPath as String, strTablename as String) as
>Boolean
>on error goto TableExists_Err

>    dim db as DAO.database
>    dim tdf as DAO.tabledef

>'initialize return value
>TableExists = FALSE

>Set db = OpenDatabase(strDbPath)

>For Each tdf in db.Tabledefs
>    If tdf.name = strTableName
>        TableExists = TRUE
>        Exit For
>    End if
>Next tdf

>TableExists_Exit:
>on error resume next
>Exit Function

>TableExists_Err:
>msgbox "TableExists" & vbcrlf & _
>err.number & vbcrlf & err.description
>Resume TableExists_Exit
>End Function



>> HELP!!
>> this generates a error were i do not get rid of it
>> what are i am doing wrong

>> it gives the error item not find in this collection (what is true
>ofcourse)
>> but error handeling does not react on this :(

>> i need to check if a table exist ( if not i want to make it if it is i
>need
>> to append fields to it)

>> thanx

>> Function DoesTableExist(sTblName As String) As Boolean
>>    Dim dbs As dao.Database
>>    Dim tbldef As dao.TableDef
>>    Dim rst As Recordset
>>    Dim x

>> On Error GoTo DoesTableExist_err
>>    Set dbs = OpenDatabase("C:\WindowsUren\NoordWind.mdb")

>>     Set tbldef = dbs.TableDefs(sTblName)
>>        x = dbs.TableDefs(sTblName).Fields.Count
>>    DoesTableExist = True

>> DoesTableExist_end:
>>     Exit Function

>> DoesTableExist_err:
>>     MsgBox Err.Number
>>     DoesTableExist = False
>>     resume     DoesTableExist_end
>> End Function



Thu, 12 Dec 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. fRefreshLinks Doesn't work if path doesn't exist

2. asyncread doesn't tell if file doesn't exists

3. files exists or not - says that it doesn't exist

4. FindFirst Doesn't Work on Table- Help

5. Doesen't doesn't exist

6. Windows Service Calling VB6 dll doesn't work but works with VB6

7. IE3 doesn't work after working with webbrowser control

8. Why LoadPicture() works on local pathes and doesn't work on the URLS

9. Work Around doesn't work for RichTextBox

10. Passing a Parameter its works and it doesn't work

11. Works/Doesn't Work

12. ActiveX-Exe: .Value=True doesn't work while direct click on button works

 

 
Powered by phpBB® Forum Software