Create a time-delay messagebox in Base

I am running Libre Office 5.2.3.3. I have a form that I created in Base that posts a timestamp to a table; similar to a punch-clock.

After the user punches in or out, there is a MsgBoxconfirmation message which the user then has to dismiss. I would like to replace the confirmation message with one that will self-dismiss after a few seconds.

I thought I could accomplish this by creating a label field and control it’s visibility by adding a few more lines to the timestamp macro. I’ve spent loads of time googling and trying and testing. But I can’t seem to figure out the syntax. In particular, I believe I’m failing to properly address the label field. Below are several examples of code that do similar things.

example 1

adapted from: Access2Base - It's about converting PEOPLE, not data

sub GetControlVal

    Dim ocControl As Object
    ocControl = ofForm.Controls("confirm1")
    MsgBox ocControl.Value
    'ocControl.Visible = False

end sub

example 2

adapted from: [Solved] Hide control (View topic) • Apache OpenOffice Community Forum

sub HideButton3
    dim button3 as object
    Button3 = StarDesktop.CurrentComponent.DrawPage.Forms.GetByIndex(0).getByName("Push Button 3")
    thiscomponent.currentcontroller.getcontrol(Button3).setVisible(False)

end sub

example 3

adapted from: [Solved] Form Control Visible/Invisible with macro (View topic) • Apache OpenOffice Community Forum

sub threeseconds
    Doc = ThisComponent
    Sheet = Doc.Sheets.getByIndex(0)
    Page = Sheet.DrawPage
    Form = Page.Forms.getByIndex(0)
    
    'txtlabel is an object of type com.sun.star.comp.forms.OButtonModel
    txtlabel = Form.getByName("confirm1")
    
    'txtlabelCtrl is an object of type com.sun.star.comp.forms.OButtonControl  
    txtlabelCtrl = Doc.CurrentController.getControl(txtlabel)
    
    'This can control object size, position, visibility, etc.
    txtlabelCtrl.setVisible(False)
    Wait 3000
    txtlabelCtrl.setVisible(True)
    
end sub

example 4

adapted from: How to Hide/Unhide Field(s) on a Base Form or a SubForm

Function ToggleShowHide(ShowHideVariable As Boolean )
    RootForm = ThisComponent.Drawpage.Forms
    MainForm = RootForm.getByName("MainForm")

    i = 0

    Do While i < MainForm.Count

    If Right(MainForm.getByIndex(i).ServiceName, 4) <> "Form" And _
    Right(MainForm.getByIndex(i).Name, 6) <> "NoHide" Then
        MainForm.getByIndex(i).EnableVisible = ShowHideVariable
    End If
    i = i + 1

    Loop
End Function

I get the general idea, but it is not clear to me which method is the one I should be using, to implement this improved messagebox feature into Base with a macro.

Note that none of the four examples actually work on my database. I show them here to illustrate the many methods I have found.

Example 3 is the simplest to incorporate. setVisible(TRUE) to display and (FALSE) to hide. You can use a label control and set the displayed time with the Wait command.

The only drawback to having hidden elements it in editing the form. Sometimes it’s in the way and has to be temporarily moved out of the way. All these are basically the same principle.

Example 1 uses Access2Base - more code necessary. Example 3 uses a button - user interface. Example 4 loops through controls to hide/reveal.

Edit: 12/11/2016

To make things easier, the code necessary is included in a working sample. Just run Form1, click the button and the push button will hide and the message will display for three seconds. After three seconds the message box will hide and the button appear. There are comments in the code explaining.

Sample: TimedLabelDisplay.odb

Almost forgot. When editing the form to insert this control, in the controls’ properties General tab, set Visible to No. this way the control is not visible until the code turns it on.

Another thought, a timed dialog.

I’d like to try example 3, but it throws an error on the second line Sheet = Doc.Sheets.getByIndex(0). I’m assuming this is because I’m running a Base program, and not a Calc program. Any suggestions how I might adapt it for Base?

Your assumption is correct. If you are going to be dealing with macros, you should read up on it. A sample has been provided in my answer.

Example is very helpful, and much appreciated.