Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2022
    Posts
    17

    Access VBA questions!

    Hi,
    If I am in the right forum, could someone help with the code below? Trying to set a blinking field. The CANDATE is the control which when there is data will run the code, when empty does nothing.
    The text box default background is White and the text is Black
    Thanks, Frank

    Private Sub Form_Timer()


    If CANDATE.IsNotNull Then
    If CANDATE.BackColor = vbWhite Then
    CANDATE.BackColor = vbRed
    CANDATE.ForeColor = vbWhite
    Else


    CANDATE.BackColor = vbWhite
    CANDATE.ForeColor = vbBlack
    End If
    End If

  2. #2
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    re forum - "Access" is kind of general, but it doesn't seem to matter much here.
    when empty does nothing.
    With that code, it is not possible that it "does nothing" - it has to process one or the other. I don't see the need for the nested IF.

    In words, if the candidate has no value, bg should be white, fc should be black. If there is a value, bg should be red and fc should be white?
    Why would you set this on form timer? Code will run every interval and regardless of what the condition is, nothing will change unless the condition changes between intervals. I don't see this as being a blinking field. If you want a blinking field, perhaps describe that in those terms.
    EDIT - if candidate is null no changes will happen. If a value was removed between intervals, whatever the properties were set to, they will stay that way.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,558
    Start indenting your code correctly.

    It will help you immensely later on when code gets bigger.

    Also use the code tag # when you post code.

    Code:
    If CANDATE.IsNotNull Then
        If CANDATE.BackColor = vbWhite Then
            CANDATE.BackColor = vbRed
            CANDATE.ForeColor = vbWhite
        Else
            CANDATE.BackColor = vbWhite
            CANDATE.ForeColor = vbBlack
        End If
    End If
    Se how much easier that is to read, even just a few lines?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    Have you tried conditional formatting?
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,935
    I'm struggling to understand what help is required. Blinks too fast? blinks too slow? doesn't blink?

    So far as I know a control does not have an .isNotNull property, so perhaps it is a compilation or runtime error? Alternatively if IsNotNull is is valid, then CANDATE is not a control but something else (activeX perhaps?) or perhaps we are not talking about VBA but .net or similar?

    And a companion to the timer property is the timer interval property. No idea if that has been set and if so to what?

    Frank - please provide more information

  6. #6
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Yeah, but I just ignored all of that and banged out a few lines that maybe would have taken care of it. However, have held on to it for lack of response. Well, it is Sunday (at least it is here).
    EDIT - Come to think of it, not much point in setting the forecolor of a control where IsNull would be True?
    #2 if it becomes red and then the value is removed before the next cycle, it could stay red.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Two MS Access questions
    By amir_9 in forum Access
    Replies: 4
    Last Post: 03-08-2012, 06:38 PM
  2. New to Access Questions
    By mneko in forum Access
    Replies: 2
    Last Post: 03-25-2011, 11:16 AM
  3. Some Access Questions
    By amegahed3 in forum Access
    Replies: 1
    Last Post: 04-11-2010, 12:24 AM
  4. HELP, Access questions.
    By brown in forum Access
    Replies: 0
    Last Post: 04-21-2009, 03:31 PM
  5. New to Access and have questions
    By MichelleFinn in forum Access
    Replies: 1
    Last Post: 04-04-2008, 06:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums