Module1模块
Option Explicit
Public AdodcPath As String '这是adodc控键共用数据库
Public userPassword As String
Public username As String
Public Sub InitializeDataPath() '对数据库的路径进行初始化,使用相对的路径,只要数据库与程序在同一目录下即可保证数据的正常访问了
If Right(App.Path, 1) <> "\" Then '是为在打包的时候可能出现无斜杆的防错吗?
AdodcPath = App.Path & "\library.mdb"
Else
AdodcPath = App.Path & "library.mdb"
End If
End Sub
登陆窗体:
Private Sub cmdOK_Click()
If intcount >= 3 Then
MsgBox "非法用户!", vbOKOnly + vbExclamation, ""
Exit Sub
End
End If
If txtuser.Text = "" Or txtPassword.Text = "" Then
MsgBox "请输入用户名与密码!", vbOKOnly + vbInformation, ""
Exit Sub
End If
With rsUserTable
rsUserTable.Find " 用户帐号 = '" & txtuser.Text & "'"
If .EOF Then
intcount = intcount + 1
MsgBox "用户名不存在!", vbOKOnly + vbInformation, ""
txtuser.Text = ""
txtuser.SetFocus
Exit Sub
End If
.Find "用户密码 ='" & txtPassword.Text & "'"
If .EOF Then
intcount = intcount + 1
MsgBox "您输入密码不正确!", vbOKOnly + vbInformation, ""
txtPassword.Text = ""
txtPassword.SetFocus
Exit Sub
End If
End With
username = txtuser.Text
userPassword = txtPassword.Text
Unload Me
Load MDIForm1
MDIForm1.Show
End Sub
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub Form_Load()
InitializeDataPath
Adodc1.ConnectionString = AdodcPath
Adodc1.RecordSource = "select * from usertable"
Adodc1.Refresh
Set rsUserTable = Adodc1.Recordset
End Sub
出错提示:
错误定位在:Adodc1.Refresh
[Microsoft][ODBC驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序
如果将Adodc1.Refresh注解掉,出现的错误是这样的:
实时错误 '91':
对象变量或 with 模块变量未设置
错误定位在:rsUserTable.Find " 用户帐号 = '" & txtuser.Text & "'"
[此贴子已经被作者于2006-11-5 1:55:47编辑过]