私は現在、プロジェクトに取り組んでいます。要件の 1 つは、ユーザーの Windows ログインを MS Access のログインとして使用することであり、そこでロールをクリックしてシステムにアクセスします。これまでにこれを行ったことはありませんが、Access でテーブルからデータを取得するログイン画面を設定しました。ユーザーの Windows ログインを正常にプルするコードがありますが、この後問題が発生しています。テーブル名は tblUser で、ユーザーは General User、HR、および Admin です。現在、テーブルには、一般ユーザー = 1、HR = 2、管理者 = 3 の番号が割り当てられたロールがあります。
The Login Screen:
Log On
General User
HR
Admin
Code that pulls the user information:
Private Sub Form_Load()
Stop
Debug.Print Environ("UserName")
Debug.Print Environ$("ComputerName")
Dim strVar As String
Dim i As Long
For i = 1 To 255
strVar = Environ$(i)
If LenB(strVar) = 0& Then Exit For
Debug.Print strVar
Next
End Sub
以下は、過去にログイン画面用に作成したコードです。すべてを描き出すと、同じプロセスのように見えますが、確かではありません。以下のコードにできることはありますか?
Private Sub btnLogin_Click()
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("tblUser", dbOpenSnapshot, dbReadOnly)
rs.FindFirst "UserName='" & Me.txtUserName & "'"
If rs.NoMatch = True Then
Me.lblWrongUser.Visible = True
Me.txtUserName.SetFocus
Exit Sub
End If
Me.lblWrongUser.Visible = False
If rs!Password <> Nz(Me.txtPassword, "") Then
Me.lblWrongPass.Visible = True
Me.txtPassword.SetFocus
Exit Sub
End If
Me.lblWrongPass.Visible = False
If rs!EmployeeType_ID = 3 Then
Dim prop As Property
On Error GoTo SetProperty
Set prop = CurrentDb.CreateProperty("AllowBypassKey", dbBoolean, False)
CurrentDb.Properties.Append prop
SetProperty:
If MsgBox("Would you like to turn on the bypass key?", vbYesNo, "Allow Bypass") = vbYes Then
CurrentDb.Properties("AllowBypassKey") = True
Else
CurrentDb.Properties("AllowBypassKey") = False
End If
End If
DoCmd.OpenForm "frmPersonal_Information"
DoCmd.Close acForm, Me.Name
End Sub
これが私が達成しようとしていることに対する十分な情報であることを願っています. さらに情報が必要な場合は、お知らせください。ありがとうございました。