如何判断ACCESS中是否存在一个表名为ABC的表,如果没有则将表A的结构拷贝过去。

解决方案 »

  1.   

    dim cn as new adodb.connetion
    dim rs as new adodb.recordset
    dim existabc as boolean
    cn.cursorlocation=aduseclient
    cn.open "provider=microsoft.jet.oledb.4.0;persist security info=false;data source=databasename;user id=uid;password=pws"
    set rs=cn.openschema(adschematable)
    existabc=false
    do until rs.eof
       if rs!table_name="ABC" then  '要注意表名的大小写
          existabc=true
          exit do 
       endif
       rs.movenext
    loop
    if existabc then
         cn.execute "select * into ABC from a where 3=2"
    endif
      

  2.   

    if existabc then
         cn.execute "select * into ABC from a where 3=2"
    endif
    改为
    if not existabc then
         cn.execute "select * into ABC from a where 3=2"
    endif
      

  3.   


    '----------------------------------------------------------------------------
    '
    'Author:lihonggen0
    'Date:2003-6-19
    '功能:获取access库中表的个数及表的名称
    '用ado怎样实现
    '工程--->引用--->Microsoft ActiveX Data Object 2.x(版本号)
    '----------------------------------------------------------------------------
    Private Sub Form_Load()
    Dim adoCN   As New ADODB.Connection                '定义数据库的连接
    Dim strCnn   As New ADODB.Recordset
    Dim I As Integer
       str1 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Northwind.MDB;Persist Security Info=False"
       adoCN.Open str1
             
       Set rstSchema = adoCN.OpenSchema(adSchemaTables)
         
       Do Until rstSchema.EOF
            If rstSchema!TABLE_TYPE = "TABLE" Then
               out = out & "Table  name:  " & _
                   rstSchema!TABLE_NAME & vbCr & _
                   "Table  type:  " & rstSchema!TABLE_TYPE & vbCr
                I = I + 1
            End If
            rstSchema.MoveNext
       Loop
       MsgBox I
       rstSchema.Close
         
       adoCN.Close
    Debug.Print out
    End Sub
      

  4.   

    这个最直接!adoCN是一个access的连接
    你用的时候改一下即可
    '*********************************************************
    '* 名称:TableExists
    '* 功能:判断表是否存在(表名)
    '* 用法:TableExists(表名) adoCN是一个access的连接
    '*********************************************************
    Public Function TableExists(findTable As String) As Boolean
        Dim rstSchema As New ADODB.Recordset
        Set rstSchema = adoCN.OpenSchema(adSchemaTables)
        rstSchema.Find "TABLE_NAME='" & findTable & "'"
        If rstSchema.EOF Then
          TableExists = False
        Else
          TableExists = True
        End If
        rstSchema.Close
    End Function
      

  5.   

    DAO访问数据库用这个,我以前用DAO的时候写的:Public Function ExistsTable(TName As String) As Boolean
        Dim dbAccess As Database
        Dim Test As String
        
        On Error Resume Next
        
        Set dbAccess = OpenDatabase(App.Path & "\dbdevice.mdb", False, False)
        ' 该名字在表名中是否存在。
        Test = dbAccess.TableDefs(TName).Name
        If Err <> 3265 Then
            ExistsTable = True
            Err = 0
        End If
        dbAccess.Close
    End Function