Dim DatabaseName As String
Dim sConnect As String
DatabaseName = App.Path & "\Anamnesis.mdb"
If Dir(DatabaseName) = "" Then
Dim dbDatabase As DAO.Database
Set dbDatabase = CreateDatabase(DatabaseName, dbLangGeneral, dbEncrypt)
        dbDatabase.Close
        Set dbDatabase = Nothing
        sConnect = "Provider=Microsoft.Jet.OLEDB.3.51;Data Source=" & DatabaseName & ";Mode=Share Deny None;Extended Properties=';COUNTRY=0;CP=1252;LANGID=0x0409';Locale Identifier=1033;Jet OLEDB:System database='';Jet OLEDB:Registry Path='';Jet OLEDB:Global Partial Bulk Ops=2"
Set ConDatabase = New ADODB.Connection
ConDatabase.Open sConnect
DoEvents
        ConDatabase.Execute "CREATE TABLE [Anamnesis] (" & _
                    "[THE_AnamnesisType] text (4)," & _
                    "[THE_AnamnesisID] text (7)," & _
                    "[THE_PatientName] text (8)," & _
                    "[THE_IDcard] text (18)," & _
                    "[THE_Sexual] text (2)," & _
                    "[THE_Birth] datetime," & _
                    "[THE_NativePlace] text (80)," & _
                    "[THE_Address] text (80)," & _
                    "[THE_Firm] text (80)," & _
                    "[THE_Employment] text (20)," & _
                    "[THE_InSectionTime] datetime," & _
                    "[THE_LeaveSectionTime] datetime," & _
                    "[THE_Goto] text (4)," & _
                    "[THE_Result] text (4)," & _
                    "[THE_Measure] text (255)," & _
                    "[THE_Diagnose] text (255)," & _
                    "[THE_Medico] text (8)," & _
                    "[THE_DiagnoseDate] datetime," & _
                    "[THE_State] text(4)," & _
                    "[THE_BorrowName] text(8)" & _
                    ")"
        
        DoEvents
        ConDatabase.Execute "CREATE TABLE [Borrow] (" & _
                    "[THE_AnamnesisType] text (4)," & _
                    "[THE_AnamnesisID] text (7)," & _
                    "[THE_PatientName] text (8)," & _
                    "[THE_IDcard] text (18)," & _
                    "[THE_BorrowName] text (8)," & _
                    "[THE_BorrowIDcard] text (18)," & _
                    "[THE_BorrowFirm] text (80)," & _
                    "[THE_Introduce] text (80)," & _
                    "[THE_Use] text (80)," & _
                    "[THE_BorrowTime] datetime," & _
                    "[THE_ReturnTime] datetime" & _
                    ")"
        Else
        sConnect = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & DatabaseName & ""
        Set ConDatabase = New ADODB.Connection
        ConDatabase.Open sConnect
    End If
我想在程序运行的时候判断一下数据库文件是否存在,如果不存在建立数据库,可老是不能建立数据库,不知问题出在哪里

解决方案 »

  1.   

    dim sql as string
    sql ="if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[表]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
    drop table [dbo].[表]" & chr(13) & "GO" & chr13 &
    "CREATE TABLE [ado].[Borrow]  (" & _
                        "[THE_AnamnesisType] text (4)," & _
                        "[THE_AnamnesisID] text (7)," & _
                        "[THE_PatientName] text (8)," & _
                        "[THE_IDcard] text (18)," & _
                        "[THE_BorrowName] text (8)," & _
                        "[THE_BorrowIDcard] text (18)," & _
                        "[THE_BorrowFirm] text (80)," & _
                        "[THE_Introduce] text (80)," & _
                        "[THE_Use] text (80)," & _
                        "[THE_BorrowTime] datetime," & _
                        "[THE_ReturnTime] datetime" & _
                        ")"
    ConDatabase.Execute sql