1
如何在access vba編輯器中設置表單以便在寫入命令後才能讀取它?我已經輸入了下面的代碼。評論部分強調了我認爲代碼可能會去的地方。如何將打開的表單設置爲只讀訪問vba?
Option Compare Database
Private Sub Command10_Click()
Dim DBS As Database
Dim rstUserPwd As Recordset
Dim bFoundMatch As Boolean
Dim txtUsername As String
Dim txtPassword As String
Dim FRM As Form
Set DBS = CurrentDb
Set rstUserPwd = DBS.OpenRecordset("qryUserPwd")
bFoundMatch = False
If rstUserPwd.RecordCount > 0 Then
rstUserPwd.MoveFirst
Do While rstUserPwd.EOF = False
If rstUserPwd![Username] = Form_frmLogin.txtUsername.Value And rstUserPwd![Password] = Form_frmLogin.txtPassword.Value Then
bFoundMatch = True
Exit Do
End If
rstUserPwd.MoveNext
Loop
End If
If bFoundMatch = True Then GoTo G1
On Error GoTo G2
G1: If rstUserPwd![Username] = "wsmith" Then
MsgBox "Access Granted"
DoCmd.Close acForm, Me.Name
DoCmd.OpenForm "AmalgamatedForm"
DoCmd.OpenForm "AgeUKRequirementsForm"
DoCmd.OpenForm "CiberRequirementsForm"
DoCmd.OpenForm "Blackbaud_ITT_ResponseForm"
DoCmd.OpenForm "Ciber_ITT_ResponseForm"
DoCmd.OpenForm "ThankQ_ITT_ResponseForm"
ElseIf rstUserPwd![Username] = "admin" Then
MsgBox "Access Granted"
DoCmd.Close acForm, Me.Name
DoCmd.OpenForm "AmalgamatedForm"
DoCmd.OpenForm "AgeUKRequirementsForm"
DoCmd.OpenForm "CiberRequirementsForm"
DoCmd.OpenForm "Blackbaud_ITT_ResponseForm"
DoCmd.OpenForm "Ciber_ITT_ResponseForm"
DoCmd.OpenForm "ThankQ_ITT_ResponseForm"
ElseIf rstUserPwd![Username] = "ageuk" Then
MsgBox "Access Granted"
DoCmd.Close acForm, Me.Name
DoCmd.OpenForm "AmalgamatedForm"
'how do i set the form in row above to read only here until exit database
DoCmd.OpenForm "AgeUKRequirementsForm"
'how do i set the form in row above to read only here until exit database
DoCmd.OpenForm "CiberRequirementsForm"
'how do i set the form in row above to read only here until exit database
DoCmd.OpenForm "Blackbaud_ITT_ResponseForm"
'how do i set the form in row above to read only here until exit database
DoCmd.OpenForm "Ciber_ITT_ResponseForm"
'how do i set the form in row above to read only here until exit database
DoCmd.OpenForm "ThankQ_ITT_ResponseForm"
'how do i set the form in row above to read only here until exit database
ElseIf rstUserPwd![Username] = "ciber" Then
MsgBox "Access Granted"
DoCmd.Close acForm, Me.Name
DoCmd.OpenForm "AmalgamatedForm"
'how do i set the form in row above to read only here until exit database
DoCmd.OpenForm "AgeUKRequirementsForm"
'how do i set the form in row above to read only here until exit database
DoCmd.OpenForm "CiberRequirementsForm"
'how do i set the form in row above to read only here until exit database
DoCmd.OpenForm "Ciber_ITT_ResponseForm"
'how do i set the form in row above to read only here until exit database
Else
G2: MsgBox "Incorrect username or password"
End If
End Sub
謝謝。它工作得很好。豎起大拇指! – user3432631