可以繞過Access本身的界面使用自定界面﹐如以下VB寫的一個界面。代碼如下:
此處為了保護后端數據庫﹐便采用兩套密碼﹐一套Access安全機制中的﹐一套是用戶登陸的(可簡單在Access安全機制中的每個密碼后面加個字串(如本例子)﹐也可采用一些運算得到不同字串加強保密)。希望以下方法對你有幫助。
Dim cnn As DAO.Database
Dim rst As DAO.Recordset
Private Sub Command1_Click()
Dim bas As Variant
Set rst = cnn.OpenRecordset("select * from 系統用戶")
rst.FindFirst "[用戶]='" & Me.Text1.Text & "' and [密碼]='" & IIf(Me.Text2.Text = "", "z", Me.Text2.Text) & "'"
If LCase(rst!用戶) = LCase(Me.Text1.Text) And rst!密碼 = IIf(Me.Text2.Text = "", "z", Me.Text2.Text) Then
Me.Visible = False
DoEvents: DoEvents: DoEvents
Dim fil As New Scripting.FileSystemObject
If Dir("C:\Molding.mde") = "" Then GoTo NEWa
If Dir("I:\" & Me.Text1.Text & ".txt") <> "" Then GoTo Copya
GoTo RunA:
Copya:
fil.DeleteFile "I:\" & Me.Text1.Text & ".txt"
fil.CopyFile "I:\Molding.mde", "c:\Molding.mde"
GoTo RunA:
NEWa:
fil.CopyFile "I:\Molding.mde", "c:\Molding.mde "
fil.CopyFile "I:\Molding.bmp", "c:\Molding.bmp"
fil.CopyFile "I:\DRAG.ico", "c:\drag.ico"
If Dir("I:\系統\" & Me.Text1.Text & ".txt") = "" Then GoTo RunA
fil.DeleteFile "I:\" & Me.Text1.Text & ".txt"
RunA:
Dim strDB As String
Dim strCmd As String
strDB = "C:\Molding.mde"
rst.FindFirst "[用戶]='a'"
bas = rst!密碼
strCmd = "C:\Program Files\Microsoft Office\Office\MSACCESS.EXE " _
& strDB & " /wrkgrp " & "I:\Short\kmq013.mdw " _
& " /user " & LCase(Me.Text1.Text) & " /pwd " & Me.Text2.Text & "9abz"
Call Shell(strCmd, vbNormalFocus)
DoEvents: DoEvents: DoEvents
End
Exit Sub
Else
MsgBox "密碼錯誤", vbCritical, "密碼"
End If
rst.Close
Set rst = Nothing
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Load()
DBEngine.DefaultUser = "系統用戶"
DBEngine.DefaultPassword = ""
DBEngine.SystemDB = "I:\Short\kmq013.mdw"
Set cnn = DBEngine.OpenDatabase("I:\molding.mde")
Set rst = cnn.OpenRecordset("select * from 系統用戶")
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then Me.Command1.SetFocus
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then Me.Text2.SetFocus
End Sub
[此贴子已经被作者于2005-5-7 14:12:47编辑过]
|