Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What's wrong with this code? 1

Status
Not open for further replies.

demax182

Technical User
Jul 13, 2004
43
US
I'm trying to create a simple welcome form. I have it's activate event using the following procedure:

Private Sub Form_Activate()

'When the database is opened display welcome user message.
'When the timer interval is reached, this form closes and opens Switchboard

If Time() < 0.5 Then
[lblMorning].Visible = True
[lblAfternoon].Visible = False
[lblEvening].Visible = False

ElseIf Time() > 0.5 And Time() < 0.75 Then
[lblMorning].Visible = False
[lblAfternoon].Visible = True
[lblEvening].Visible = False

ElseIf Time() > 0.75 Then
[lblMorning].Visible = False
[lblAfternoon].Visible = False
[lblEvening].Visible = True
End If
End Sub

I have created all the appropriate labels. "Good Morning" displays, but "Good Afternoon" does not display. I can't figure out why? Thanks in advance for your help.

Mike
 
How are ya demax182 . . . . .

The [blue]Time Function[/blue] returns the [blue]System Time[/blue] and is improper for your use. Not only that, but the code runs so fast [blue]only one secnario gets displayed at best.[/blue] Also consider [blue]Activate[/blue] is basically a one time affair and is rarely used. More importantly, you don't get to pick up the Time Function again (to parse thru your secnarios) until you open the form again.

Copy/paste your modified code below to the [blue]On Timer[/blue] event of the form:
Code:
[blue]   [purple]Static flg As Integer[/purple] [green]'Stays in memory while form is open.[/green]
      
   If flg = 0 Then
      Me!lblMorning.Visible = True
      Me!lblAfternoon.Visible = False
      Me!lblEvening.Visible = False
      [purple]flg = flg + 1[/purple]
   ElseIf flg = 1 Then
      Me!lblMorning.Visible = False
      Me!lblAfternoon.Visible = True
      Me!lblEvening.Visible = False
      [purple]flg = flg + 1[/purple]
   ElseIf flg = 2 Then
      Me!lblMorning.Visible = False
      Me!lblAfternoon.Visible = False
      Me!lblEvening.Visible = True
      [purple]flg = flg + 1[/purple]
   Else
      Me.TimerInterval = 0 [green]'Stop Timer[/green]
      [green]'Close Form
      'Open SwitchBoard[/green]
   End If[/blue]
Then copy/paste the following code to the [blue]On Load[/blue] event of the form:
Code:
[blue]Me.TimerInterval = 250 [green]'Time in milliseconds[/green][/blue]
Thats it . . . give it a whirl and let me know . . .

Calvin.gif
See Ya! . . . . . .
 
Thank you AceMan,

Actually, I failed to exactly specify exactly what I was trying to do. I'm trying to create a "Welcome Form". During the morning, I want to form to specify "Good Morning" only. I have 3 labels on the form, and I tried to code it so that when it opens, one label is visible while the other labels are not. The visible label coinciding with the time of day. Thank you.

Mike
 
Private Sub Form_Load()

If Time() < #12:00:00 PM# Then
lblMorning.Visible = True
lblAfternoon.Visible = False
lblEvening.Visible = False
ElseIf Time() > #12:00:00 PM# And Time() < #6:00:00 PM# Then
lblMorning.Visible = False
lblAfternoon.Visible = True
lblEvening.Visible = False
Else lblMorning.Visible = False
lblAfternoon.Visible = False
lblEvening.Visible = True
End If
End Sub


PaulF
 
Mike . . . .

Sorry about that, was thinking of something else. . .

It should work as you have it. [purple]Are you waiting for the proper time to open the form?[/purple]

[blue]0.50 = 12:00 pm
0.75 = 6:00 pm
[/blue]

Also in [blue]form design view[/blue], if you set the [blue]Visible Property[/blue] of the labels to false, you can shorten the code.
Code:
[blue]      If Time() < 0.5 Then
      Me!lblMorning.Visible = True
   ElseIf Time() < 0.75 Then
      Me!lblAfternoon.Visible = True
   Else
      Me!lblEvening.Visible = True
   End If[/blue]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top