PDA

View Full Version : Solved: Splash Effect Object on Userform



dcraker
10-27-2008, 10:36 AM
Forgive me if this has already been accomplished before but I haven't seen it. Could be worthy of an entry to the Hall of Fame if there is a solution for it. :yes
I know about the Splash Screen, and I haven't needed it, but I have it stored JIC. But I wonder if it can be used for objects on a Userform while it is open.

What I would like is; When the user updates an existing entry, then the label saying Saved would appear for about 4 or 5 seconds, informing the User that changes have been saved. My goal would be is to have a Splash effect on the Userform, I am thinking of using a Label object. It would say Saved in an area on the Userform, hopefully the text will be red. Then it would disappear until the next time it was saved again.

Any other ideas that would acquire the same type of effect would be welcomed and tried as well. I would even consider the Title bar of the Userform also temporarily displaying it.
It would be an extension of the userform I had assistance with in this thread (http://www.vbaexpress.com/forum/showthread.php?t=22693), that I have received excellent help with

jproffer
10-27-2008, 11:20 AM
Like this?

You may have to play with the event that triggers the label.visible property, but it works. It locks the user out while it's sleeping, but it works.

GTO
10-27-2008, 11:37 AM
Greetings dcraker,

You could use this, if you wanted the lbl to be a "flashing sign" so-to-speak.

The 'Flash' sub would go in the userform's module...

Private Sub CommandButton3_Click() 'save button
Dim LastRow As Object, TF As String

Flash ("lblSaved")

'sheet4 is the ultimate Database page
Set LastRow = Sheet4.Range("A" & Rows.Count).End(xlUp)

'...Statements...

End Sub

Private Sub Flash(strCtrl As String)
Dim sngEndTime As Single

sngEndTime = Timer + 5

Do While Timer < sngEndTime
If Not Me.Controls(strCtrl).ForeColor = &H0& Then
Me.Controls(strCtrl).ForeColor = &H0&
Else
Me.Controls(strCtrl).ForeColor = &HFF&
End If
Delay 0.5
Loop

Delay

Me.Controls(strCtrl).ForeColor = &H8000000F
End Sub

...and 'Delay' would go in a standard module.

Option Explicit
Function Delay(Optional SecondFraction As Single = 0.2)
Dim sngTimeHack As Single, dtmDate As Date

sngTimeHack = Timer: dtmDate = Date

If sngTimeHack + SecondFraction < 86400 Then
Do
DoEvents
Loop While Timer < (sngTimeHack + SecondFraction)
Else
If dtmDate = Date Then
Do
DoEvents
Loop While dtmDate = Date
End If

sngTimeHack = (sngTimeHack + SecondFraction) - 86400
If DateAdd("d", 1, dtmDate) = Date Then
Do
DoEvents
Loop While Timer < sngTimeHack
End If
End If
End Function

Hope this helps,

Mark

Bob Phillips
10-27-2008, 11:59 AM
Here's another.

In the form



Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Label1.Visible = True
Application.OnTime Now + TimeSerial(0, 0, 5), "HideLabel"
End Sub


set the ontime from whichever event you see fit.

And in a standard code module



Private mpForm As UserForm1

Public Sub ShowForm()

Set mpForm = New UserForm1

mpForm.Show

Set mpForm = Nothing
End Sub

Public Sub HideLabel()
On Error Resume Next
mpForm.Label1.Visible = False
mpForm.Repaint
End Sub

dcraker
10-27-2008, 02:07 PM
Wow, this is good stuff here.
I have tried all three

jproffer
Yours does very well, I didn't really like the fact that it locked up the sheet during this time. I could use it as a excuse that it takes about 2 seconds (reducing 5000 to 2000). But it isn't exactly what I am looking for. I may use this if I am not able to figure out xld's code to suit. See my comment to xld's below

GTO
I loaded yours in, and didn't get it to work at all. I love the idea, but it isn't what I am looking for at this time. But definitely is something that I will explore for one of the other projects that I am cooking up. I am also going to test it some more tonight or tomorrow.

xld
Yours does exactly as what I was looking for in a new workbook test, but I am having trouble with your mpForm name in the real workbook test. I tried to attach it to a commandbutton versus an exit from a textbox with no-go, it would still save but the label never appears. Wondering if part of it is that when the save button is pressed, at the end of the save code, it will "reset the form" for a new entry. As an FYI, I do have Userform1 repeated a number of times in the Userform Code module, could/would the mpForm name have a serious side effect on it?
My error is coming up with "User-defined type not defined". I don't know why it doesn't do this in the new empty workbook, but with a loaded one that has Userform1 in a number of places, it won't work at all.
On this line, will tell me the errorPrivate mpForm As UserForm1


Thank you jproffer, GTO and xld. I am thrilled to have this, and hope to have something that will help me and any others that could/would be interested in something like this also

David

Bob Phillips
10-27-2008, 04:14 PM
See if this helps

dcraker
10-28-2008, 08:10 AM
:thumb thanks xld, it worked great for me. It does exactly what I was looking for. I believe I know why I had a hard time now with it. It had to do with where I put the code. I was putting it at the beginning of my codes, whereas it should have been to the end of it. It does a beautiful job of it. Label1.Visible = True
Application.OnTime Now + TimeSerial(0, 0, 5), "HideLabel"

I wouldn't mind seeing these entries being a part of a bigger thing. I wonder if there is a proper name for this, so that others could easily find this, because I didn't know what I was going to call it.
Is it worthy of being in the Hall of fame? I would vote yes.

Thanks again to all that helped, I love learning these. I still call myself an amateur on it.

David

Bob Phillips
10-28-2008, 10:52 AM
Is it worthy of being in the Hall of fame? I would vote yes.

Oh no! I think the Hall of Fame deserves a more encompassing solution than this, this was just a technique really.