2017-05-03 83 views
0

OpenFormがアプリケーションに再現されました。デコンパイル/コンパクト化して2回修復しました。OpenFormが取り消されたエラーが再発しました

エラーを投げるコード: 「オープンメニューフォーム DoCmd.OpenForm "メニュー"、acNormal、、、、acWindowNormal

私は、このエラーが発生しました初めて、私は変更することで、それを解決:

DoCmd.OpenForm "Menu", acNormal, "", "", , acNormal 

これは例外を受け、私の手順です

DoCmd.OpenForm "Menu", acNormal, , , , acWindowNormal. 
Private Sub Login(recordSet As DAO.recordSet, PERSAL As String, Password As String) 
On Error GoTo Login_ErrHandler 

'Check to see if the recordset actually contains rows 
If Not (recordSet.EOF And recordSet.BOF) Then 
    recordSet.MoveFirst 'Unnecessary in this case, but still a good habit 

    'See if credentials match data 
    Do 
     If (recordSet!User_ID = PERSAL And recordSet!Password = Password) Then 

      'Open Menu form 
      DoCmd.OpenForm "Menu" 
      ' Form_Menu.op 

      recordSet.Close 'Close the recordset 
      Set recordSet = Nothing 'Clean up 

      'Close Login form 
      DoCmd.Close acForm, "Login" 

      Exit Do 
     End If 

     recordSet.MoveNext 

     If (recordSet.EOF Or recordSet.BOF) Then 
      MsgBox "Your credentials are incorrect or you are not registered." 

      Exit Do 
     End If 
    Loop 

    'Match the values entered for PERSAL nr. and password fields with a row in User table 

Else 

    MsgBox "There are no records in the recordset." 

    recordSet.Close 'Close the recordset 
    Set recordSet = Nothing 'Clean up 

End If 

Form_Login.txtUser_ID.SetFocus 

Login_ErrHandler: 
If Err = 2501 Then 
    'MsgBox "No data to display" 
    DoCmd.Hourglass False 
    Resume Login_ErrHandler 
' Else 

' MsgBox Err.Description, vbCritical 
End If 

End Sub 

今回はこのエラーを修正しますか?

+1

質問は何ですか? –

+0

テーブル行の値を1つチェックするためにループは必要ありません。 * Menu *には 'OnOpen'または' OnLoad'イベントがありますか?その再コードソースも確認してください。 – Parfait

+0

レコードセットオブジェクトを渡す理由代わりにDLookup()を使用すると思います。 – June7

答えて

0

次のSQLでパラメータクエリを作成します:コードを仮定

PARAMETERS [prmUserId] Text (255), [prmPassword] Text (255); 
SELECT User_ID, Password 
FROM YOUR_TABLE_NAME 
WHERE ((([User_ID])=[prmUserId]) AND (([Password])=[prmPassword])); 

は、ログインフォームの背後にある:

Private Sub Login(ByVal PERSAL As String, ByVal Password As String) 
    On Error GoTo Login_ErrHandler 

    Dim qdf As DAO.QueryDef 
    Set qdf = CurrentDb().QueryDefs("YourQueryName") 'Change to your query name 
     qdf.Parameters("[prmUserId]").Value = PERSAL 
     qdf.Parameters("[prmPassword]").Value = Password 

    Dim rs As DAO.recordSet 
    Set rs = qdf.OpenRecordset() 

    'No records 
    If rs.EOF Then 
     MsgBox "Your credentials are incorrect or you are not registered." 
     Me.txtUser_ID.SetFocus 
     GoTo Leave 
    End If 

    'User found 

    'Close Login Form 
    DoCmd.Close acForm, Me.Name, acSavePrompt 

    'Open Form 
    DoCmd.OpenForm "Menu", acNormal, , , acFormPropertySettings, acWindowNormal 

Leave: 
    On Error Resume Next 
     rs.Close 
    Set rs = Nothing 
     qdf.Close 
    Set qdf = Nothing 
    On Error GoTo 0 
    Exit Sub 

Login_ErrHandler: 
    MsgBox Err.Number & " - " & Err.Description, vbCritical 
    Resume Leave 
End Sub 
+0

Kostas私はパラメータ化されたクエリを検索し、それが私が使用していないSQL Serverと関係があることを発見しました。 SQL Serverが必要ですか? –

+0

ms-accessで簡単なクエリです。単にクエリを作成し、提供されたSQLを貼り付けます。 –

+0

@Marcus Mackaku "YOUR_TABLE_NAME"をテーブルの実際の名前に変更するのを忘れないでください。 –

関連する問題