2 Tasks 1 button

Kira

Registered User.
Local time
Today, 09:08
Joined
Jul 7, 2008
Messages
40
I want to have two different tasks run when I click the "logout" button on my form. Both work fine independently, but I do not know how to get them to both work at the same time. One is a Macro entitled "Open Work Hours" and the other is a code in visual basic which I place as "event procedure" in the event box. I was trying to put them both in the On Click event box. How do I do this?
 
The problem, I think, is that Access executes one thing after the other without waiting for the system to finish the first task. The only way we prevent this in VBA code is to place the DoEvents function between the two commands that are being executed.

First event
DoEvents
Second event

There's no way I know to do this using Macros and procedures in the Events Box. I think you need to move the entire thing into VBA code and using it as I dhowed you above.
 
So like:

Code:
Private Sub btnLogOut_Click()
    Dim DB As DAO.Database
    Dim RST As DAO.Recordset
        
    Set DB = CurrentDb()
    Set RST = DB.OpenRecordset("LoginLogout", dbOpenDynaset)
        
        With RST
            .FindLast "UserName = '" & txtUserName & "'"
            .Edit
            !TimeOut = Time()
            .Update
            .Close
        End With
        
    Me.txtUserName = ""
End Sub

DoEvent

Code:
Private Sub btnLogOut_Click()
      whatever i need to type to get it to open a form
End Sub

Is that right?
 
That needs to be DoEvents with an S. The code needs to all be in the same sub; you can't have two subs with the same name:

Code:
Private Sub btnLogOut_Click()
    Dim DB As DAO.Database
    Dim RST As DAO.Recordset
        
    Set DB = CurrentDb()
    Set RST = DB.OpenRecordset("LoginLogout", dbOpenDynaset)
        
        With RST
            .FindLast "UserName = '" & txtUserName & "'"
            .Edit
            !TimeOut = Time()
            .Update
            .Close
        End With
        
    Me.txtUserName = ""

[B]DoEvents[/B]

'Do whatever you need to do to open form here
End Sub
 

Users who are viewing this thread

Back
Top Bottom