if not exists(select 1 from sysobjects where name = 'yourtablename')
create table yourtablename
...

解决方案 »

  1.   

    我用access没有sysobjects 怎么办啊
      

  2.   

    是什么数据库??如果是SQLSERVER可以用zhuzhichao(竹之草) 的方法。如果是ACCESS,就得定义数据库对象,然后循环一下看看有没有表名和自己的表名一样的表。
      

  3.   

    将错就错嘛,在ERR处写代码。
      

  4.   

    同意 sam_xcx(sam) 
    循环也对啊
      

  5.   

    感谢您使用微软产品。在VB中,我们可以通过 Error Handler 来判断是否在当前数据库中有一个重名的表。
    如下例子介绍了如何通过ADOX在Access中处理一个特发事件:
    Use ADOX
    ========
    'Sample for AccessDim cnn As New Connection
        Dim cat As New Catalog
        Dim tbl As Table
        cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Data Source= c:\Program Files\Microsoft Office\" & _
            "Office\Samples\Northwind.mdb;"
        Set cat.ActiveConnection = cnnfor each tbl in cat.tables    if tbl.name="mytable" then
            msgbox "exist!"
        end if
    next 更详细的信息,请参阅http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnado/html/msdn_adorosest.asp - 微软全球技术中心 VB开发支持本帖子仅供CSDN的用户作为参考信息使用。其内容不具备任何法律保障。您需要考虑到并承担使用此信息可能带来的风险。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
    为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。
      

  6.   

    使用adodb.connection对象的OPENSCHEAM()方法得到acess数据库中的所有的数据表,到一个
    Recordset对象中,然后就可以得到了
      

  7.   

    Public Sub OpenSchemaX()   Dim cnn1 As ADODB.Connection
       Dim rstSchema As ADODB.Recordset
       Dim strCnn As String
          
       Set cnn1 = New ADODB.Connection
          strCnn = "Provider=sqloledb;" & _
          "Data Source=srv;Initial Catalog=pubs;User Id=sa;Password=; "
       cnn1.Open strCnn
          
       Set rstSchema = cnn1.OpenSchema(adSchemaTables)
       
       Do Until rstSchema.EOF
          Debug.Print "Table name: " & _
             rstSchema!TABLE_NAME & vbCr & _
             "Table type: " & rstSchema!TABLE_TYPE & vbCr
          rstSchema.MoveNext
       Loop
       rstSchema.Close
       
       cnn1.Close
       
    End Sub