'先引用Microsoft DAO 2.5/3.51 Compatibility Library
'打开一个数据库
Public Function OpenDatabase()
        On Error GoTo err
        Dim MyPath As String
        FrmMain.CommonDialog1.CancelError = True
        FrmMain.CommonDialog1.Filter = "所有文件|*.*|(*.mdb)数据库文件|*.mdb"
        FrmMain.CommonDialog1.ShowOpen
        MyPath = FrmMain.CommonDialog1.FileName
         On Error GoTo 0
        On Error GoTo err1
        Set m_DataBase = Workspaces(0).OpenDatabase(MyPath)  //打开数据库
        Set m_RecordSet = m_DataBase.OpenRecordset("电阻温度系数", dbOpenTable)//打开数据集       ImpedanceOfRx = NowRecordset.Fields("电阻").Value//读取字段
       TroughTemperature = NowRecordset.Fields("温度").Value
        Exit Function
err:
       Exit Function
err1:
        Exit Function
End Function

解决方案 »

  1.   

    将数据库文件放到执行文件同一目录下,在程序中用app.path将得至的路径附给dao就可以访问数据库了!
      

  2.   

    用数据绑定控件,但要真正开发数据库程序,最好用ADO,绑定控件效率太低,而且不灵活.
      

  3.   

    1、先引用ADO
    2、定义记录集
       Dim rs as New ADODB.RecordSet
       rs.CursorLocation=UserClient
       rs.Open "select * from czyb where czyxm='"&Text1.Text&"'",conn,adOpenKeyset,adLockOptimistic,adCmdText
    然后判断一下操作员是否存在,密码是否正确!
      

  4.   

    假设你的密码存放在sysinfo.mdb中的sysinfo表中的"OPpass"字段在登录窗体中写如下程序:
    Private CN As New ADODB.Connection
    Private RS As New ADODB.Recordset
    Private LogPass As String
    Private Sub Form_Load() '在窗体建立时便读出该字段的内容
    CN.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
                App.Path & "\sysinfo.mdb;Persist Security Info=False"
    RS.CursorLocation = adUseClient
    RS.Open "SELECT * from sysinfo", CN, adOpenDynamic, adLockReadOnly
    LogPass = UCase(Trim(RS.Fields("OPPass")))
    RS.Close
    End Sub
    Private Sub cmdOK_Click() '在TxtPass(Text控件)输入密码后的处理
        
        If UCase(TxtPass.Text) = LogPass Then
         ' 处理密码正确后的事情   
        Else
            MsgBox "无效的密码,请重试!", vbOKOnly + vbcirtical, "登录"
            TxtPass.SetFocus
            SendKeys "{Home}+{End}"
        End If
    End Sub以上程序在VB6中通过.
      

  5.   

    抱歉,发错目标贴了~
    不过里面也有VB绑ACESS的内容.
      

  6.   

    在登录窗体中写如下程序:
        Dim Cnxn As New ADODB.connection
        Dim Crst As New ADODB.Recordset
        dim strCnxn as string
        AccessFileName as string '数据库文件路径
        strCnxn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & AccessFileName & ";Persist Security Info=False"
        Set Cnxn = New ADODB.connection
        Cnxn.Open strCnxn
        Set Crst = New ADODB.Recordset
        Set Crst.ActiveConnection = Cnxn
        Crst.Source = "Select * From Table1 where (UserName='" & txtUserName & "') And (PassWord='" & txtPassWord & "')"
        Crst.Open , , adOpenStatic, adLockPessimistic
        if crst.recordCount=0 then
           '说明用户名txtUserName和密码txtPassWord不存在
        else
           '说明用户名txtUserName和密码txtPassWord存在
        Crst.Close
        Cnxn.Close
        Set Crst = Nothing
        Set Cnxn = Nothing
      

  7.   

    我这里有新做的vb和access连接的信用卡交易系统
    你要的话,就给我qq留个email
    qq:
    15770732