Results 1 to 4 of 4
  1. #1
    Magnus1982 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2017
    Posts
    29

    Call update method white out addnew or edit method

    Hi All

    I have my access base with forms and one tabel . Everithing was working. Till i try implement some code for Login and User . Login and USer is working perfectrly but now when i try to fill some field in forms I have message " Call method Update or Cancel Update whiteout method AddNew or Edit'

    My database is simple :

    One tabel
    And 5 forms

    First Form writing first 5 row in tabel
    Second Form writing next 5 row in table
    etc

    Befoure when Login and User wasn't present in my base avery thing was warking coretly.

    Login and user - It is one tabel with data (paswords ,logins etc)
    and login form

    Can somebody help me with this ?


    Below code for login (I found it on internet)

    Private intLogAttempt As Integer
    Private Sub cboUser_GotFocus()
    cboUser.Dropdown

    End Sub
    Private Sub cmdExit_Click()
    Response = MsgBox("Czy chcesz zamknąć aplikacje?", vbYesNo + vbQuestion, "Zamknij Aplikacje")

    If Response = vbYes Then
    Application.Quit
    End If
    End Sub
    Private Sub cmdLogin_Click()
    Call Login

    End Sub
    Private Sub cmdLogin_Enter()
    Call Login
    End Sub
    Public Sub Form_Load()

    txtFocus.SetFocus 'txtFocus is a textbox control with height, widht and positions set to zero

    End Sub
    Public Sub Login()

    On Error GoTo ErrorHandler:
    If IsNull([cboUser]) = True Then 'Check UserName
    MsgBox "Użytkownik jest wymagany"

    ElseIf IsNull([txtPassword]) = True Then 'Check Password
    MsgBox "Hasło jest wymagane"

    Else

    'Compare value of txtPassword with the saved Password in tblUser
    If Me.txtPassword.Value = DLookup("Password", "tblUsers", "[UserName]='" & Me.cboUser.Value & "'") Then
    strUser = Me.cboUser.Value 'Set the value of strUser declared as Global Variable
    strRole = DLookup("Role", "tblUsers", "[UserName]='" & Me.cboUser.Value & "'") 'set the value of strRole declared as Global Variable
    DoCmd.Close acForm, "frmLogin", acSaveNo
    'MsgBox "Witam ponownie, " & strUser, vbOKOnly, "Welcome"
    DoCmd.OpenForm "Menu", acNormal, "", "", , acNormal

    Else
    MsgBox "Hasło nie poprawne.Spróbuj ponownie.", vbOKOnly, "Złe Hasło"
    intLogAttempt = intLogAttempt + 1
    txtPassword.SetFocus

    End If

    End If



    'Check if the user has 3 wrong log-in attempts and close the application
    If intLogAttempt = 3 Then
    MsgBox "Nie masz dostępu skontaktuj się z Administratorem" & vbCrLf & vbCrLf & _
    "Aplikacja wyłączy się.", vbCritical, "Zabroniony dostęp!"
    Application.Quit
    End If

    ErrorHandler:
    End Sub
    Private Sub Form_Current()
    DoCmd.Maximize
    End Sub

  2. #2
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Is there any indication of which line is causing the error?

  3. #3
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    but now when i try to fill some field in forms
    I don't think the login code you posted is causing the error. The action above is. It looks like perhaps an error with updating a DAO recordset.
    If the error popup shows a 'debug' button, click that and it will highlight the error line in your code.

  4. #4
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    Code:
    Public Sub Login()
        On Error GoTo ErrorHandler:
        If IsNull([cboUser]) = True Then 'Check UserName
            MsgBox "Użytkownik jest wymagany"
        ElseIf IsNull([txtPassword]) = True Then 'Check Password
            MsgBox "Hasło jest wymagane"
        Else
            'Compare value of txtPassword with the saved Password in tblUser
            If Me.txtPassword.Value = DLookup("Password", "tblUsers", "[UserName]='" & Me.cboUser.Value & "'") Then
                strUser = Me.cboUser.Value 'Set the value of strUser declared as Global Variable
                strRole = DLookup("Role", "tblUsers", "[UserName]='" & Me.cboUser.Value & "'") 'set the value of strRole declared as Global Variable
                DoCmd.Close acForm, "frmLogin", acSaveNo
                'MsgBox "Witam ponownie, " & strUser, vbOKOnly, "Welcome"
                DoCmd.OpenForm "Menu", acNormal, "", "", , acNormal
            Else
                MsgBox "Hasło nie poprawne.Spróbuj ponownie.", vbOKOnly, "Złe Hasło"
                intLogAttempt = intLogAttempt + 1
                txtPassword.SetFocus
            End If
        End If
        'Check if the user has 3 wrong log-in attempts and close the application
        If intLogAttempt = 3 Then
            MsgBox "Nie masz dostępu skontaktuj się z Administratorem" & vbCrLf & vbCrLf & _
            "Aplikacja wyłączy się.", vbCritical, "Zabroniony dostęp!"
            Application.Quit
        End If
    ErrorHandler:
        MsgBox Err.Number & ", " & Err.Description & " in sub Login of form frmLogin"
    End Sub
    Your existing error handler does nothing but ignore errors without any notification. Suggest you add the above red code line.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Update or CancelUpdate without AddNew or Edit
    By westcoastbmx in forum Forms
    Replies: 5
    Last Post: 11-07-2019, 09:01 PM
  2. update multiple records, best method
    By NikoTheBowHunter in forum Database Design
    Replies: 2
    Last Post: 06-08-2017, 08:59 AM
  3. Replies: 6
    Last Post: 06-25-2016, 02:56 PM
  4. Replies: 1
    Last Post: 07-18-2015, 07:59 PM
  5. DAO .Edit "Method or data member not found"
    By GraeagleBill in forum Programming
    Replies: 3
    Last Post: 09-05-2013, 02:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums