Hello !! - How To Close Form Automatically - Access 2007

MKader12

New member
Local time
Today, 07:58
Joined
May 23, 2012
Messages
5
Hello All,

I need Help with the below script i got over the net, i want to close the form once the messages end.

any ideas what to write and where within the code ??



Code:
Option Compare Database
Option Explicit

Public txtScrollStatus As String



Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Form_Open
    
    Dim MyDb As Database
    Dim sMessage As String
    Dim sMessages As String
    Dim rMessage As Recordset

    Set MyDb = CurrentDb()

    sMessage = ""
    sMessages = ""
    sMessages = "SELECT tMessage.Message FROM tMessage WHERE (((tMessage.Message) Is Not Null));"

    Set rMessage = MyDb.OpenRecordset(sMessages)
        rMessage.MoveFirst
    Do Until rMessage.EOF = True
        sMessage = sMessage & Space(10) & rMessage!Message
    If Not rMessage.EOF Then rMessage.MoveNext

    Loop

    TimerInterval = 100
    Me.lMessage.Caption = sMessage
    txtScrollStatus = sMessage
    
    Set MyDb = Nothing
    Set rMessage = Nothing

Exit_Form_Open:
    Exit Sub
Err_Form_Open:
    MsgBox Err.Number & " " & Err.Description
    Resume Exit_Form_Open
    
 End Sub

Private Sub Form_Timer()
On Error GoTo Err_Form_Timer
    
    
    
    Me.lMessage.Caption = Mid(Me.lMessage.Caption, 2, (Len(Me.lMessage.Caption) - 1)) & Left(Me.lMessage.Caption, 1)
    
    SysCmd acSysCmdSetStatus, txtScrollStatus
    txtScrollStatus = Mid(txtScrollStatus, 2, (Len(txtScrollStatus) - 1)) & Left(txtScrollStatus, 1)


Exit_Form_Timer:
    Exit Sub
Err_Form_Timer:
    MsgBox Err.Number & " " & Err.Description
    Resume Exit_Form_Timer
    
End Sub

Thanks,
MK
 
Hello MK, Welcome to the Forum, to close a Form programatically you have to use the DoCmd.Close.. But your description is not really clear.. Your code is not too.. Could you explain what you are trying to do? You can lookup the internet to find resource on DoCmd.
Good Luck.
 
Hello pr2-eugin, first of all, thanks for your reply and for the code, it's a scroll text code.
I will separate it to make it clear.
I already searched the web for DoCmd, however, all i found is commands based on a "Click Button".

Thanks,
MK

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Option Compare Database Option Explicit Public txtScrollStatus As String Private Sub Form_Open(Cancel As Integer) On Error GoTo Err_Form_Open Dim MyDb As Database Dim sMessage As String Dim sMessages As String Dim rMessage As Recordset Set MyDb = CurrentDb() sMessage = "" sMessages = "" sMessages = "SELECT tMessage.Message FROM tMessage WHERE (((tMessage.Message) Is Not Null));" Set rMessage = MyDb.OpenRecordset(sMessages) rMessage.MoveFirst Do Until rMessage.EOF = True sMessage = sMessage & Space(10) & rMessage!Message If Not rMessage.EOF Then rMessage.MoveNext Loop TimerInterval = 100 Me.lMessage.Caption = sMessage txtScrollStatus = sMessage Set MyDb = Nothing Set rMessage = Nothing Exit_Form_Open: Exit Sub Err_Form_Open: MsgBox Err.Number & " " & Err.Description Resume Exit_Form_Open End Sub

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Private Sub Form_Timer() On Error GoTo Err_Form_Timer Me.lMessage.Caption = Mid(Me.lMessage.Caption, 2, (Len(Me.lMessage.Caption) - 1)) & Left(Me.lMessage.Caption, 1) SysCmd acSysCmdSetStatus, txtScrollStatus txtScrollStatus = Mid(txtScrollStatus, 2, (Len(txtScrollStatus) - 1)) & Left(txtScrollStatus, 1) Exit_Form_Timer: Exit Sub Err_Form_Timer: MsgBox Err.Number & " " & Err.Description Resume Exit_Form_Timer End Sub
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
No it does not only work with OnClick.. where ever you place it; it will execute.. I said I did not understand your code was because,

* You only have two Sub - OnTimer and OnOpen

What does it do? I mean if you place the docmd.close at the end of the code, just before
Code:
Exit_Form_Open:
    Exit Sub
Err_Form_Open:
    MsgBox Err.Number & " " & Err.Description
    Resume Exit_Form_Open
Then what happens is, once opened it closes.

* If you place it in the onTimer event.. say if you have the timer for 20 seconds then your form will be closed after opening for 20 seconds maybe failing to do anything at all.

So DoCmd is just a line of code can be placed anywhere, it will be executed as per the line of control. The real question is WHY do you want to close the form? give some scenarios, examples, explain WHAT YOU ARE TRYING TO DO..
 
Thanks again for your reply, basically, it's a "scroll text" like the news string.

this is why i want to close auto.

I tried the DoCmd.Close and it close straight away even with the timer set to 30 sec.

please help ...
 

Users who are viewing this thread

Back
Top Bottom