0

I'm currently trying to write a script that requires a notification bar in the form. The script itself is responsible for creating invoices, which works so well. However, I want to display errors and information in a label. The label is already in a frame and I have the following code as well:

    Private Function notificate(msg As String, Optional title As String)
        lbl_notification.Caption = msg

        If Not IsEmpty(title) Then
            frm_notification.Caption = title
        Else
            frm_notification.Caption = ""
        End If

        frm_notification.Visible = True

        Application.Wait (Now + TimeValue("0:00:10"))

        frm_notification.Visible = False

        frm_notification.Caption = ""
        lbl_notification.Caption = ""
        notificate = True
    End Function

(I am not sure if it should be a subroutine or a function.)

How do I get this function to work so that I can use my form at the same time, if that is possible?

feetwet
  • 3,248
  • 7
  • 46
  • 84
  • You may be interested in https://stackoverflow.com/questions/39224308/non-blocking-toast-like-notifications-for-microsoft-access-vba – Andre Aug 08 '18 at 09:14
  • Just to make you aware: The verb that corresponds to the noun *notification* is *to notify*. (The word you chose will likely be understood just as well, it just sounds a little funny.) – Inarion Aug 08 '18 at 09:16
  • @inarion ohh ^^ thanks for that. Yeah i'm sorry if there are some errors. I'm from germany – Tobias Sessler Aug 08 '18 at 09:17
  • No need to feel sorry. We all make mistakes. And improvements mostly come from practicing. So keep doing that. :) – Inarion Aug 08 '18 at 09:23
  • And regarding your actual question: I highly recommend checking out the link @Andre posted above. Trying to achieve it in native VBA would involve a lot of messy `Application.Run` calls, I guess. – Inarion Aug 08 '18 at 09:36
  • I did, but it did't really help. So I've tried a few things and have finally done it ^ ^ I'll comment the solution right back to the question – Tobias Sessler Aug 08 '18 at 10:07
  • I realized after having a look at the repository that linked question points to that there is no source code available... As such I can't really recommend it anymore. – Inarion Aug 08 '18 at 12:22

1 Answers1

0

Well, I've tried it a bit and finally got it done. Meanwhile, my subroutine looks like this:

    Private Sub notificate(msg As String, Optional title As String)
        ofEvent = False

        lbl_notification.Caption = msg
        If Not IsEmpty(title) Then
            frm_notification.Caption = title
        Else
            frm_notification.Caption = ""
        End If

        frm_notification.Visible = True
        frm_notification.Transparency = 0.5

        For i = 1 To 1000000
            DoEvents
            If ofEvent Then
                GoTo GoOn
            End If
        Next i

    GoOn:

        frm_notification.Visible = False

        frm_notification.Caption = ""
        lbl_notification.Caption = ""
    End Sub

And as you can already imagine, the following is in my frame in the click function

    ofEvent = True

And ofEvent is a global boolean Variable