Solved

How to modity code in timer sub to be a conditional

Posted on 2009-04-01
14
307 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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 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 Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

740 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