Solved close the form after 10 second

FahadTiger

Member
Local time
Today, 04:55
Joined
Jun 20, 2021
Messages
115
Hi experts.. I get some code below from CHAT-GPT to close form after 10 second when mouse not move
is there any suggest ..thanks
Private Declare PtrSafe Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type

Private m_x As Long
Private m_y As Long
Private m_TimeElapsed As Double
Private m_StopWatchStarted As Boolean
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
m_x = X
m_y = Y
If Not m_StopWatchStarted Then
m_StopWatchStarted = True
Timer.Enabled = True
End If
End Sub

Private Sub Timer_Timer()
m_TimeElapsed = m_TimeElapsed + Timer.Interval / 1000
If m_TimeElapsed >= 10 Then
Timer.Enabled = False
m_StopWatchStarted = False
m_TimeElapsed = 0
Me.Close
End If
End Sub
 
The simple version:
Code:
Option Explicit
Option Compare Database

Private LastMoved As Date

Private Sub Form_Load()
  LastMoved = Now
  Me.TimerInterval = 1000
End Sub

Private Sub Form_Timer()
  If DateDiff("s", LastMoved, Now) > 10 Then
    DoCmd.Close acForm, Me.Name
  End If
End Sub

Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  LastMoved = Now
End Sub

It gets more complex if you have lots of controls on your form and subforms, form headers or form footers as well, but that should give you a start.
 
The simple version:
Code:
Option Explicit
Option Compare Database

Private LastMoved As Date

Private Sub Form_Load()
  LastMoved = Now
  Me.TimerInterval = 1000
End Sub

Private Sub Form_Timer()
  If DateDiff("s", LastMoved, Now) > 10 Then
    DoCmd.Close acForm, Me.Name
  End If
End Sub

Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  LastMoved = Now
End Sub

It gets more complex if you have lots of controls on your form and subforms, form headers or form footers as well, but that should give you a start.
thank you cheekybuddha.. its simple and good for now..I dont know if I will get more complex at future
 
Out of curiosity, what was the exact question you asked ChatGPT?
 
Just as a side note, we have seen other code posted here by ChatGPT for which there is some question as to accuracy. It is entirely possible that ChatGPT doesn't know (or doesn't care) about differences between VBA, VB scripting, and VB6.
 

Users who are viewing this thread

Back
Top Bottom