2017-11-05 52 views
-2

が見つかりません。ログインをクリックすると、「コンパイルエラー:メソッドまたはデータメンバーが見つかりません」というメッセージが表示されます。どうすれば修正できますか?ありがとう!コードはMicrosoft Accessのコンパイルエラー:メソッドまたはデータメンバは、私は私のデータベースのためのシンプルなログインフォームを作成してい

Option Compare Database 
Option Explicit 

Private Sub btnLogin_Click() 
    Dim rs As Recordset 

    Set rs = CurrentDb.OpenRecordset("TBL:Staff", dbOpenSnapshot, dbReadOnly) 

    rs.FindFirst "UserName='" & Me.txtUserName & "'" 

    If rs.NoMatch = True Then 
     Me.lblWrongUser.Visible = True 
     Me.txtUserName.SetFocus 
     Exit Sub 
     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 
    DoCmd.OpenForm "FRM:Customer" 
    DoCmd.Close acForm, Me.Name 
End Sub 
+0

を返しますが存在します。 –

+0

行4は、私はエリックは、コードの行を意味すると思うエラー –

+0

の原因となっています。 –

答えて

0

です。

チェック、ユーザー名とパスワードの値は、データベースに存在する場合、単純なDCountで見た後、提供されています。ユーザー名/パスワードの場合

はエラーを与える行を入力してください、それは> 0返されない場合、それは0

Private Sub btnLogin_Click() 
    With Me 
     'Username/Password - value provided? 
     If IsNull(.txtUserName.Value) Or IsNull(.txtPassword.Value) Then 
      MsgBox "Both fields required.", vbExclamation 
      Exit Sub 
     End If 

     'Username exists in Table? 
     If DCount("*", "Staff", "UserName='" & .txtUserName.Value & "'") = 0 Then 
      .lblWrongUser.Visible = True 
      .txtUserName.SetFocus 
      Exit Sub 
     End If 

     'Password exists in Table? 
     If DCount("*", "Staff", "UserName='" & .txtUserName.Value & _ 
           "' And Password='" & .txtPassword.Value & "'") = 0 Then 
      .lblWrongPass.Visible = True 
      .txtPassword.SetFocus 
      Exit Sub 
     End If 
    End With 

    'Code will reach here only if supplied username and passowrd are correct 
    With DoCmd 
     .OpenForm "Customer", acNormal, , , acFormPropertySettings, acWindowNormal 
     .Close acForm, Me.Name, acSavePrompt 
    End With 
End Sub 
関連する問題