Ask Your Question

Create a time-delay messagebox in Base [closed]

asked 2016-12-11 05:29:38 +0100

LeftyMaus gravatar image

updated 2020-09-16 15:05:23 +0100

Alex Kemp gravatar image

I am running Libre Office 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:

sub GetControlVal

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

end sub

example 2

adapted from:

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

end sub

example 3

adapted from:

sub threeseconds
    Doc = ThisComponent
    Sheet = Doc.Sheets.getByIndex(0)
    Page = Sheet.DrawPage
    Form = Page.Forms.getByIndex(0)

    'txtlabel is an object of type
    txtlabel = Form.getByName("confirm1")

    'txtlabelCtrl is an object of type  
    txtlabelCtrl = Doc.CurrentController.getControl(txtlabel)

    'This can control object size, position, visibility, etc.
    Wait 3000

end sub

example 4

adapted from:

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

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.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2020-09-16 15:05:39.936831


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

LeftyMaus gravatar imageLeftyMaus ( 2016-12-11 23:54:05 +0100 )edit

1 Answer

Sort by » oldest newest most voted

answered 2016-12-11 06:03:45 +0100

Ratslinger gravatar image

updated 2016-12-12 02:26:13 +0100

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

edit flag offensive delete link more


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.

Ratslinger gravatar imageRatslinger ( 2016-12-11 06:53:14 +0100 )edit

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?

LeftyMaus gravatar imageLeftyMaus ( 2016-12-12 00:07:45 +0100 )edit

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.

Ratslinger gravatar imageRatslinger ( 2016-12-12 02:28:11 +0100 )edit

Example is very helpful, and much appreciated.

LeftyMaus gravatar imageLeftyMaus ( 2016-12-12 03:00:51 +0100 )edit

Question Tools

1 follower


Asked: 2016-12-11 05:29:38 +0100

Seen: 569 times

Last updated: Dec 12 '16