Solved

How to modity code in timer sub to be a conditional

Posted on 2009-04-01
14
282 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
  • 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
 

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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

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 350 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

929 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now