Page 4 of 4 FirstFirst 1234
Results 46 to 57 of 57
  1. #46
    data808 is offline Noob
    Windows 10 Access 2013 32bit
    Join Date
    Aug 2012
    Posts
    727

    Quote Originally Posted by Micron View Post
    you might have a corrupt code page. Try decompile and re-compiling.
    http://www.fmsinc.com/microsoftacces.../decompile.asp
    Thanks @Micron. I got it working again. I mentioned what I did to make it go away. lol

  2. #47
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    Yup, saw that. At the top of the forum page is a link "How to attach files". Generally it's best to post your file rather than pm it.

    EDIT - actually, I don't think you can pm attachments here.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #48
    data808 is offline Noob
    Windows 10 Access 2013 32bit
    Join Date
    Aug 2012
    Posts
    727
    Found out that everything seems to work in the On Unload event even when the user closes the app from the taskbar except for Me.Undo. I tested MsgBoxes with other triggers to see what is happening and everything gets triggered except for the Me.Undo. That is why a record cannot be prevented from saving if the user closes the app by taskbar. So annoying.

    Will report back if I find anymore details.

  4. #49
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    I thought I had mentioned that record would have been saved by then?, so nothing to undo?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #50
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    Thought you were going to post a db copy. Or am I mixing up my threads?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #51
    data808 is offline Noob
    Windows 10 Access 2013 32bit
    Join Date
    Aug 2012
    Posts
    727
    Quote Originally Posted by Welshgasman View Post
    I thought I had mentioned that record would have been saved by then?, so nothing to undo?
    Would you know when the record is actually saved because I felt like it's still Dirty. Basically I start typing the username which makes it Dirty then immediately after that, I close app by taskbar. So is the record being saved first because Access thinks it's like a power outage or something and does the save then closes?

  7. #52
    data808 is offline Noob
    Windows 10 Access 2013 32bit
    Join Date
    Aug 2012
    Posts
    727
    Quote Originally Posted by Micron View Post
    Thought you were going to post a db copy. Or am I mixing up my threads?
    No @Micron. You are correct. I was going to post my DB but emailed to @Gicu first to see if he could figure out any solutions. He hasn't gotten back to me yet so if he can't figure it out then I'll post it here. Thanks.

  8. #53
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    Right after either the BeforeInsert or BeforeUpdate event I would have thought?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  9. #54
    data808 is offline Noob
    Windows 10 Access 2013 32bit
    Join Date
    Aug 2012
    Posts
    727
    Quote Originally Posted by Welshgasman View Post
    Right after either the BeforeInsert or BeforeUpdate event I would have thought?
    Can it do that even without any code in those events? Is that a safety feature built into Access to preserve data during outages?

    Is there a way to write VBA to do a check if a button was clicked or not? Like I could code in the Before Update event to check if login button was clicked and if it wasn't then Me.Undo? Would that work?

    And if the login button was clicked then I don't want the "recordsave" to undo because that means they are actually trying to log in and I would want the record to save that data.

  10. #55
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    One way to cause a record to be saved is to move off of it, and that can include something as benign clicking some other control on a form. So there's probably not much point in worrying about whether or not a button was clicked. We are 4 pages of posts into this issue so in absence of a db to troubleshoot I'm just going to wish you luck and disengage.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  11. #56
    data808 is offline Noob
    Windows 10 Access 2013 32bit
    Join Date
    Aug 2012
    Posts
    727
    Quote Originally Posted by Micron View Post
    One way to cause a record to be saved is to move off of it, and that can include something as benign clicking some other control on a form. So there's probably not much point in worrying about whether or not a button was clicked. We are 4 pages of posts into this issue so in absence of a db to troubleshoot I'm just going to wish you luck and disengage.
    Yeah I knew records do save when you move from one record to another thats why in other forms where I have the users enter records, I have code to take care of that stuff in the Before Update events. However, I also just tested another form that has this code I am referring to and it's resides in the Before Update event with a Docmd.RunCommand acCmdUndo and that did not trigger when closing the app by taskbar. Not sure if Docmd Undo makes a difference from Me.Undo but in all cases, it seems that Access has something built in as a safety to preserve data when there are electrical outages and I think closing from taskbar is something that replicates that outage scenario. Too bad Access doesn't implement something to counter this and be able to tell the difference when a user closes by taskbar or when there is an electrical outage.

    Anyway, no worries. I totally understand your disengagement. If @Gicu can't figure out something I will post the DB. Just want to say thank you so much to everyone who has tried to help. You guys are awesome!

  12. #57
    data808 is offline Noob
    Windows 10 Access 2013 32bit
    Join Date
    Aug 2012
    Posts
    727
    Thanks everyone for the help. @Gicu was able to help me come up with something for the Before Update event which gave the result for what I was looking for. Just thought I was post the solution in case it can help someone else out there with similar issues. Here is the code that was needed to achieve what I wanted. It all started with figuring out why the form was always Dirty even if the user didn't type anything into the form. As @Gicu pointed out, we removed this from the Form_Current event:

    Me.txtUsername = UCase(Me.txtUsername)

    Instead it was moved over to the Key Press "KeyAscii = Asc(UCase(Chr(KeyAscii)))" and After Update "Me.txtUsername = UCase(Me.txtUsername)" events and then the Dirty issue went away.

    Then to resolve records from being saved with missing or no data when the user closed app by taskbar, I added this VBA to the following events:

    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    
    If IsNull(Me.txtLoginDateTime) And Me.Visible = True Then
        Me.Undo
        Exit Sub
    End If
    
    
    End Sub
    Code:
    Private Sub Form_Unload(Cancel As Integer)
    
    If Me.Visible = False Then
        [Forms]![Login]![txtLogoutDateTime] = Now()
        Exit Sub
    End If
    
    
    End Sub
    Code:
    Private Sub cmdLogin_Click()
    
    Dim validCredentials As Integer
    Dim userLevel As Variant
    Dim ID As Integer
    validCredentials = DCount("Username", "[tblUser]", "[Username] ='" & txtUsername & _
    "' AND [Password]='" & txtPassword & "'")
            
    If IsNull(Me.txtUsername) Then
        MsgBox "Please Enter Username", vbInformation, "Username Required"
        Me.txtUsername.SetFocus
    ElseIf IsNull(Me.txtPassword) Then
        MsgBox "Please Enter Password", vbInformation, "Password Required"
        Me.txtPassword.SetFocus
    Else
        ID = DLookup("UserID", "tblUser", "Username = '" & Me.txtUsername.Value & "'")
        If validCredentials = 1 And Me.txtPassword = "password" Then
            Me.Undo
            DoCmd.Close
            MsgBox "Please Change Password", vbInformation, "New Password Required!"
            DoCmd.OpenForm "Change Password", , , "[UserID] = " & ID
        Else
            If validCredentials = 1 Then
            userLevel = Nz(DLookup("UserSecurity", "[tblUser]", "[Username]='" & Me.txtUsername & "'"), "")
            If userLevel = "Admin" Then
                Me.Visible = False
                Me.txtLoginDateTime = Now()
                Me.Dirty = False
                'Me.Visible = False
                DoCmd.OpenForm "Main Menu_admin"
            Else
                Me.Visible = False
                Me.txtLoginDateTime = Now()
                Me.Dirty = False
                DoCmd.OpenForm "Splash Screen Load"
            End If
        Else
            MsgBox "Invalid Username Or Password!", vbExclamation, "UNAUTHORIZED!"
            Me.txtPassword.SetFocus
        End If
    End If
    End If
    Exit Sub
    
    End Sub
    The code for the login remained very close to the original code except for the order of when the form became hidden and when the record would be saved. To work with the Before Update event, I had to make sure the form would be hidden before it tries to save the record so that if the user closed the app by taskbar while still filling out or at the very least has the login form open and hasn't logged in yet, the Me.Undo would trigger so that the login date/time stamp would not occur. The Unload event will only trigger if the login form is hidden while it closes because if the form is hidden, that means the user had already logged in.

    Thanks again to everyone who helped with this issue. Appreciate it.

Page 4 of 4 FirstFirst 1234
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Code VBA for minimize application in Taskbar (Access)
    By ZakariaAadel in forum Programming
    Replies: 1
    Last Post: 11-14-2020, 07:38 AM
  2. Replies: 6
    Last Post: 12-08-2019, 04:28 AM
  3. Replies: 4
    Last Post: 01-11-2016, 08:50 AM
  4. Prevent Pinning of Access to Taskbar
    By Perceptus in forum Access
    Replies: 8
    Last Post: 07-07-2015, 11:33 AM
  5. Replies: 3
    Last Post: 03-17-2014, 10:23 AM

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