如何在访问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
答案 0 :(得分:4)
您可以使用 DataMode 选项以只读方式打开表单。
DoCmd.OpenForm "Ciber_ITT_ResponseForm", DataMode:=acFormReadOnly