Set Fil = Fso.GetFile(App.Path & "\db.ini") '使用活动路径
上面这句话不通。
INI文件中的路径你读取了吗?
  

解决方案 »

  1.   


    '首先必须定义读取INI文件的API函数
    ''从INI文件中读写的WINAPI文件定义Declare Function GetPrivateProfileString Lib "kerneL32" _
    Alias "GetPrivateProfileStringA" (ByVal lpApplicationName _
    As String, ByVal lpKeyName As Any, ByVal lpDefault As _
    String, ByVal lpReturnedString As String, ByVal nSize As _
    Long, ByVal lpFilename As String) As LongDeclare Function writeprivateprofilestring Lib "kerneL32" _
    Alias "writeprivateprofilestringa" (ByVal lpApplicationName As String, _
    ByVal lpKeyName As Any, lpstring As Any, ByVal lpFilename _
    As String) As LongDeclare Function SendMessage Lib "user32" Alias "SendMessageA" _
    (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Integer _
    , ByVal lParam As Long) As Long‘然后写一函数读取INI文件
    ''从INI文件中读取数据
    Public Function readini(appname, keyname As String, _
    filename As String) As String
    Dim inireturn As String
       inireturn = String(255, Chr(0))
       readini = Left(inireturn, GetPrivateProfileString _
       (appname, ByVal keyname, "", inireturn, _
       Len(inireturn), filename))
    End Function’下面的句子读取了INI文件中ACCESS段中定义的数据库位置,你写的要根据需要修改
    g_dbname = readini("ACCESS", "dbname", inipath)            ''数据库所在目录
      

  2.   

    下面是相对应的INI文件写法
    g_dbname定义在模块中;sale.ini[parameters]
    didian=1
    KW=1
    FK=3
    zd=3
    CK=1
    shuilv=0.17
    xiee=10000
    kaipiao=T
    gongsi=1[access]
    dsn=
    dbname=D:\cmis\sale.mdb
    dbserver=
      

  3.   


    其他的一些相应函数
    ''得到应用程序的当前的位置和路径
    Public Function getapppath()
    Dim path$
    path$ = App.path
    If Right$(path$, 1) <> "\" Then path$ = path$ + "\"
    getapppath = path$
    End Function
    inipath = getapppath() & "sale.ini"DBEngine.inipath = inipath
      

  4.   

    我的初始化文件放在Module1中,代码如下:Option Explicit
    Public cnn As String
    Public Conn As ADODB.ConnectionSub Main()
        Dim ini1 As New clsIniFile
        Dim strFile As String
        If App.PrevInstance Then
            MsgBox ("程序已经运行,不能再次装载。"), vbExclamation
            End
        End If
        
        If Not (FileExists(App.Path & "\db.ini")) Then
            MsgBox "初始化文件丢失", vbOKOnly, "严重错误"
            End
        End If
        
        Load frmSplash
        frmSplash.Show
        delay 0
        Screen.MousePointer = vbHourglass
        DoEvents
        
     '   Load frmMain
     '   frmMain.Enabled = False
        Load frmMain1
        frmMain1.Enabled = False
      
        Set Conn = New ADODB.Connection
      
        ini1.File = App.Path & "\db.ini"
        strFile = ini1.GetSetting("系统", "数据文件")
        If Not FileExists(strFile) Then
            MsgBox "数据文件找不到.请首先进行系统设置->数据文件选择,然后退出系统,重新进入.", vbOKOnly, "提示"
            With frmMain1
         '   With frmMain
            .mnuQuery.Visible = False
            .mnuFund.Visible = False
            .mnuEquip.Visible = False
            .mnuPublicBase.Visible = False
            .Enabled = True
            End With
            frmLogin.Visible = False
        Else
            '设置连接字符串
            'ACCESS2000格式
           ' cnn = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Jet OLEDB:Database Password=lq;Data Source=" & strFile
            'ACCESS97格式
            cnn = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Jet OLEDB:Database Password=lq;Data Source=" & strFile
            '打开数据库
            frmLogin.Show
            On Error GoTo errDB
            Conn.Open cnn
            On Error GoTo 0
        End If
    1:    Unload frmSplash
        Screen.MousePointer = vbArrow
        Exit Sub
    errDB:
            MsgBox "数据文件打不开.请首先进行系统设置->数据文件选择,然后退出系统,重新进入.", vbOKOnly, "提示"
            With frmMain1
         '   With frmMain
            .mnuQuery.Visible = False
            .mnuFund.Visible = False
            .mnuEquip.Visible = False
            .mnuPublicBase.Visible = False
            .Enabled = True
            End With
            frmLogin.Visible = False
            Resume 1
            Exit Sub
    End Sub
    别的文件使用该数据库都正常