Solved

How to modity code in timer sub to be a conditional

Posted on 2009-04-01
14
270 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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 …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

757 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

22 Experts available now in Live!

Get 1:1 Help Now