那个这次我重建了一个数据库和表那个程序这样写通过了Public DataPath As String
Public DataConnectString As StringPrivate Sub Form_Load()DataPath = App.Path + "\db2.mdb"
    DataConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DataPath + ";Persist Security Info=False" + ";Jet OLEDB:Database Password="Adodc1.ConnectionString = DataConnectStringEnd SubPrivate Sub Command1_Click()
On Error Resume Next
Dim MPassword As String Adodc1.RecordSource = "select * from wht where name='" & Text1.Text & "'"
 Adodc1.Refresh
      If Adodc1.Recordset.RecordCount > 0 Then
          MPassword = Adodc1.Recordset.Fields("password")
          If Text1.Text = MPassword Then
                               
                         Form2.Show               Unload Me
          Else
              MsgBox "密码不正确,请您确认后重新输入", , "界面管理登陆"
              Text2.Text = ""
              Text2.SetFocus
          End If
      Else
          MsgBox "对不起 没有此用户的信息", , "界面管理登陆"
          Text1.Text = ""
          Text2.Text = ""
      End If
  
End Sub
运行没有问题但是我像把那个前面的那个加载数据库的那个写在Module1.bas上 能够被这个工程的所有form调用 怎么就不行了呢

解决方案 »

  1.   

    Module1.bas中的代码:Public DataPath As String
    Public DataConnectString As String
    Public Sub Main()
        DataPath = App.Path + "\db2.mdb"
        DataConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DataPath + ";Persist Security Info=False" + ";Jet OLEDB:Database Password=prowind"
        adoCon.Open (DataConnectString)
        Form1.Show
    End Sub那个form1是个登陆窗口
    代码如下Private Sub Command1_Click()
    On Error Resume Next
    Dim MPassword As String
    Adodc1.ConnectionString = DataConnectString
     Adodc1.RecordSource = "select * from wht where name='" & Text1.Text & "'"
     Adodc1.Refresh
          If Adodc1.Recordset.RecordCount > 0 Then
              MPassword = Adodc1.Recordset.Fields("password")
              If Text1.Text = MPassword Then
                                   
                             Form2.Show               Unload Me
              Else
                  MsgBox "密码不正确,请您确认后重新输入", , "界面管理登陆"
                  Text2.Text = ""
                  Text2.SetFocus
              End If
          Else
              MsgBox "对不起 没有此用户的信息", , "界面管理登陆"
              Text1.Text = ""
              Text2.Text = ""
          End If
      
    End Sub
    怎么这样改写后 运行 出现那个 未发现数据库名称并且没制定默认的驱动程序请问这个如何改写啊 谢谢
      

  2.   

    错误原因可能是由于你的启动对像不是sub main() ,而是form1窗体。你检查看是不是这个出错了。
      

  3.   

    1. 你的 Adodc1 没看到在哪声明的?2. 你的程序应该从 Sub Main() 入口。你在设计模式时,按一下 F8 ,看调试器给你定位在 Private Sub Form_Load() 内,还是在 Public Sub Main()。 如果不是在 Public Sub Main(),你要从工程属性中选择启动窗口为 Sub Main 。