1、在准备建一个新表的时候,如何判断该表是否已存在?
2、昨天如何用函数求出来?比如今天可以用date()?有没有专门表达昨天的函数?

解决方案 »

  1.   

    1.
    Private Sub Command28_Click()
    Dim db As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    db.ConnectionString = "provider=microsoft.jet.oledb.4.0;" & "data source=" & App.Path & "\dev.mdb"
    db.OpenIf ExistTable(db, rs, "表名") = True Then
        MsgBox "存在"
    Else
        MsgBox "不存在"
    End If
    End SubPrivate Function ExistTable(db As ADODB.Connection, rs As ADODB.Recordset, tablename As String) As Boolean
    Dim i As Long, ii As Long
    Dim tempName As StringSet rs = db.OpenSchema(adSchemaTables)
         
    ii = rs.Fields.CountDo While Not rs.EOF
        If Trim(LCase(rs!TABLE_NAME)) = Trim(LCase(tablename)) Then
            ExistTable = True
            Exit Do
        End If
        rs.MoveNext
    Loop
    End Function2.
    MsgBox Date - 1
      

  2.   

    2.
    DateAdd("d", -1, data)
      

  3.   

    Const NameNotInCollection = 3265
    Dim DB As DatabasePrivate Function ExistsTableQuery(TName As String) As Boolean
      Dim Test As String
      On Error Resume Next
        
      ' 檢查這個名稱是否出現在 Tables collection 中:
      Test = DB.TableDefs(TName).Name
      If Err <> NameNotInCollection Then
        ExistsTableQuery = True
        ' 重設 Err 預設值為 0
        Err = 0
        ' 檢查這個名稱是否出現在 Queries collection 中:
        Test = DB.QueryDefs(TName$).Name
        If Err <> NameNotInCollection Then
          ExistsTableQuery = True
        End If
      End If
    End FunctionPrivate Sub Form_Load()
      Set DB = DBEngine.Workspaces(0).Opendatabase("Biblio.mdb")
      Debug.Print "BadTable "; IIf(ExistsTableQuery("BadTableName"), "", "不"); "存在."
      Debug.Print "Authors "; IIf(ExistsTableQuery("Authors"), "", "不"); "存在."
    End Sub2:MsgBox DateAdd("d", -1, Date)
      

  4.   

    DateAdd("d", -1, date)
    不好意思,是date
    前一个月就是DateAdd("m", -1, date)
      

  5.   

    如果用rs.open表,如果表不存在的话,就会返回错误码,这样是不是会简单一些?
    date-1谢谢。等待给分。
      

  6.   

    如果用rs.open表,如果表不存在的话,就会返回错误码,这样是不是会简单一些?
    date-1谢谢。等待给分。
      

  7.   

    我用data1.recordsource=表名,当表不存在的时候,会返回一个错误的代码,可不可以用这个代码来判断?这个代码是不是固定的?