?
Solved

How to modity code in timer sub to be a conditional

Posted on 2009-04-01
14
Medium Priority
?
318 Views
Last Modified: 2013-12-25
Ok, my question is how can i switch between to way of displaying the text associated with the blinking.  Meaning if this is true show this (blinking text) if not show this ( non-blinking text) same value.  When i wrap the with block in a if statment using a fuction for the true/ false value is hangs Access.  Any ideas !!???
Private Sub Form_Load()
     custAgent(sn("cust_number")) Then
            Me.TimerInterval = 90
            Forms!f_builder.txtXCustNum = sn("Customer_number")
            Forms!f_builder.txtXCustNum.ForeColor = 255
        
        Else
            Forms!f_builder.txtXCustNum = IIf(IsNull(sn("Customer_number")), "", sn("Customer_number"))
        End If
 
end sub
 
Private Sub Form_Timer()
 
    With Forms!f_builder.txtXCustNum
        .ForeColor = (IIf(.ForeColor = vbRed, vbWhite, vbRed))
    End With
 
 
    Me!lblClock.Caption = Format(Now, "dddd, mmm d yyyy, hh:mm:ss AMPM")
End Sub

Open in new window

0
Comment
Question by:thirsty4knowledge
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 4
14 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 24042909
Is txtXCustNum part of the form you are in now or another form? if on current form, you can just do Me.txtXCustNum


Your timerinterval is a bit short, less than a second? extend it a little
0
 
LVL 10

Expert Comment

by:ALaRiva
ID: 24042941
Your IF statement is not formed correctly.

You have:
custAgent(sn("cust_number")) Then

You are missing the Keyword IF.  You also need to be sure that custAgent() is returning a boolean (true/false) value.

HTH
- Anthony
0
 
LVL 10

Expert Comment

by:ALaRiva
ID: 24042957
good catch rockiroads.
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 

Author Comment

by:thirsty4knowledge
ID: 24042984
Ok, this is a copy/ paste error but the error still has merrit.  I cant find a way to set sub_form timer based on a conditional!  Any ideas... also the function dose in fact return a boolean value.
0
 
LVL 10

Expert Comment

by:ALaRiva
ID: 24043102
Try this code.

Also, modify your timer interval to something higher, as rockiroads stated.
Private Sub Form_Load()
     If custAgent(sn("cust_number")) Then
            Me.TimerInterval = 90 
            Forms!f_builder.txtXCustNum = sn("Customer_number")
            Forms!f_builder.txtXCustNum.ForeColor = 255 
            Me.Timer.Enabled = True
        Else
            Forms!f_builder.txtXCustNum = IIf(IsNull(sn("Customer_number")), "", sn("Customer_number"))
            Me.Timer.Enabled = False
        End If
 
end sub
 
Private Sub Form_Timer()
 
    With Forms!f_builder.txtXCustNum
        .ForeColor = (IIf(.ForeColor = vbRed, vbWhite, vbRed))
    End With
 
    Me!lblClock.Caption = Format(Now, "dddd, mmm d yyyy, hh:mm:ss AMPM")
End Sub

Open in new window

0
 
LVL 10

Expert Comment

by:ALaRiva
ID: 24043114
Additional Note:
Set the Timer's enabled property default to FALSE.
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24043139
Cheers ALaRiva :)

You can switch off the timer, if thats what you mean Me.TimerInterval = 0 switches it off.
0
 

Author Comment

by:thirsty4knowledge
ID: 24043145
rockiroads:,

Yes,  txtXCustNum is part of the current vlue, im not sure how that solves the problem?  I would love something like below but the function contains loops that seem to tie up resources.
Private Sub Form_Timer()
 
  if custAgent(cust_number) Then
    With Forms!f_builder.txtXCustNum
        .ForeColor = (IIf(.ForeColor = vbRed, vbWhite, vbRed))
    End With
  end if 
 
 
    Me!lblClock.Caption = Format(Now, "dddd, mmm d yyyy, hh:mm:ss AMPM")
End Sub

Open in new window

0
 
LVL 65

Accepted Solution

by:
rockiroads earned 1400 total points
ID: 24043202
it wont solve the problem but tidies up your code and was just a recommendation. there is no need to reference a form field like that when you can simply do Me.txtXCustNum

Set the TimerInterval to blink it, set it to 0 to stop it
0
 

Author Comment

by:thirsty4knowledge
ID: 24043536
ok, guess i was making it harder than what it need to be.. thanks for everyones.. quick responses!  
0
 

Author Closing Comment

by:thirsty4knowledge
ID: 31565510
You are the man!!
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24043578
No worries. Did you try AlaRiva's approach is enabling/disabling the timer? Looks like that would work also.
0
 

Author Comment

by:thirsty4knowledge
ID: 24043607

I tried but it didn't like me trying to access the timer object like that....? So plus i need to test and push up to production like yesterday.. thanks again!
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24043684
Cool, regarding me.timer then, it looks like its a vb thing, and not available in vba.
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Suggested Courses
Course of the Month11 days, 9 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question