Code for label flash when 2 Totals do not match

Joe8915

Registered User.
Local time
Today, 01:16
Joined
Sep 9, 2002
Messages
820
This should be an easy for anyone, but not for me. Still on a learning curve on writing codes

What I am trying to accomplish, is if one total do not match another total, I need to make the label flash. The trick is as follows.
I have a Main Form which has a total amt, then I have a Sub Form that has a total amt. If the Sub Form total amt do not match the Main Form amt, make the Sub Form label flash. I know I have to set it on the timer, but I don’t know how to write the code. And where do I place the code? Main Form or the Sub Form.

Any help would be appreciated.

Thanks
 
Joe,

On the subform, use the OnCurrent event to put this code:

Code:
If Me.SubformsTotalField <> Forms![YourMainForm]![MainFormsTotalField] Then
   Me.ThatLabel.Forecolor = 255
End If

That changes the subform's total to red if they're not equal. If you want
it to flash then you really do have to use the timer. Set the timer to a
number like 250 (experiment).

Put the above code in the OnTimer event and change it to:

Code:
If Me.SubformsTotalField <> Forms![YourMainForm]![MainFormsTotalField] Then
   Me.ThatLabel.visible = Not Me.ThatLabel.visible
Else
   Me.ThatLabel.Visible = True
End If

Hope it's worth it ...

wayne
 
Wayne, thanks for helping me out on this, I am getting error msg. Please review the code

This is the Code I have so far

Private Sub Form_Timer()
If Me.tbldsc Account Numberstext14 <> Forms![qryprocurementlog]![qryprocurement logtext378] Then
Me.Label15.Visible = Not Me.Label15.Visible
Else
Me.Label15.Visible = True



End Sub

My subform is called = TblDsc Account Numbers
On my subform total text Field is called = text14
On my subform label Field is call Label15

My Main Form is called = Qryprocurementlog
My Main Form text field is called = text378
 
You need to learn how to use a proper naming convention for your db objects. Spaces should never be used to name an object. Because you have spaces in your form names then you have to enclose the object name with brackets. You did not seperate your form from the text box in the If statement. You do not need the form name if you are using the Me statement since the Me is referring to the current from from which the code is called. I also do not see an end if.

Code:
If Me.text14 <> Forms![qryprocurementlog]![qryprocurement].[logtext378] Then
     Me.Label15.Visible = Not Me.Label15.Visible
Else
     Me.Label15.Visible = True
End If
 
ghudson

I am about sharp as marble, thanks for taking a look at this. I pasted the code. What I am getting now an error., that it can't find QryProcrurement log. I check the record source and it shows QryProcrurement log.

Any Ideas (what a stupid question) for you guys

I appreciate the both of you looking at this
 
ghudson

I just noticed something in the code

Reads:

If Me.text14 <> Forms![qryprocurementlog]![qryprocurement].[logtext378] Then
Me.Label15.Visible = Not Me.Label15.Visible
Else
Me.Label15.Visible = True
End If

Maybe Should Read

If Me.text14 <> Forms![qryprocurementlog]![qryprocurementlog].[text378] Then
Me.Label15.Visible = Not Me.Label15.Visible
Else
Me.Label15.Visible = True
End If

Also I notice you did not put a space between qryprocurement and log, even though my record source shows qryprocurement log. Just a thought
 
Rich

I new somebody would say that. My form is called qryprocurement log, this when I started real early in access. I shoud have called it FrmprocurementLog, but its too late now, that was about 2 years ago. Like I said before I am sharp as marble. Thanks for the input anyway, but if you have an idea, please let me know. Been working on this problem for 4 hours
 
Your @#$&*object names is confusing those trying to help you. It is never too late to go back and fix an improperly coded db. ;)

Go back to Waynes post and use his example with your funky object [forms & text box] names and try again with Waynes code suggestion. Remember to enclose your object names with brackets [] since you have spaces in your object names.
 
Well guys thanks for all the help. Here was the final out come. The following code works

If Me.Text14 <> Forms![tblview record]![Text378] Then
Me.Label15.Visible = Not Me.Label15.Visible
Else
Me.Label15.Visible = True
End If
End Sub

I know I had some funky names.

But once again thanks to all of yo
 
Joe,

Good to see that you have it worked out.

BUT, txt14 and Label15 are names that Access provides. You can name
them something else.

Wayne
 
Code:
[color=green]'   Just my view...
'
'   As everyone has suggested, use better Control Names.
'      (Do not leave them the same as their Control Source.)
'      (Adding a naming convention always fixes that.)
'
'   Where possible don't use Control Names.
'      (Example, use Parent instead of the Parent form's name.)
'      (That would have saved a few problems.)
'
'   If used more than once then hard code the name in one place only.
'      (Example, hard code a variable and use that everywhere.)
'
'   If used only in one place then hard code it where it is used.
'      (It saves screen real estate that could be better used elsewhere.)
'
'   Don't use Wizard produced code.
'      (Reason, it can always be improved.)
'
'   Try not to blink at your users.
'      (If you must blink then keep it above 700 milliseconds.)
'      (What seems like a good idea at the time is often only just that.)
'[/color]
Private Sub Form_Timer()
    Dim strControlName As String
    
    strControlName = "lblBlinkingLabel"
    
    If Me.txtSubFormTotal <> Me.Parent.txtParentTotal Then
        Me(strControlName).Visible = Not Me(strControlName).Visible
    Else
        Me(strControlName).Visible = True
    End If

End Sub
[color=green]'
'   Don't stop looking at your code just because it happens to work.
'      (Reason, not just your current code but all your
'       subsequent code may fall short of the mark.)
'
'   And everything else I forgot to mention.
'
'   Regards,
'   Chris.[/color]
 
Chris

I was kinda afraid to ask anymore questions here, I think I had a few people a little *** at me.

Thanks for all the hot tips, as you can tell I am new at this.

Belive it or not, I am trying to make this code work now. What I am trying to accomplish is,

If the field "contracttype" = "CO" and

If field Const_Description equal = true (or has text in it)

Then make, Const_Description.Visible = Not Me.Const_Description.Visible

So far this what I have

Private Sub Form_Timer()
If Me.ContractType = "co" Then
Me.Const_Description.Visible = Not Me.Const_Description.Visible

End If
End Sub


Once again thanks to all and I didn't mean to get anybody confused on what I was trying to do. :)
 
Code:
If Me.[contracttype] = "CO" Then
     Me.[Const_Description].Visible = True
Else
     Me.[Const_Description].Visible = False
End If
 
Once again thanks ghudson, works like a charm. I am just going to have to get me a beginners book for writing codes.

Any Suggestions?
 
You are welcome.

I highly recommend that you learn how to use the built-in Access help for VBA. It has a lot of good info and it will detail the parameters that the functions require. Most of the functions have sample code that show how to use it.
 

Users who are viewing this thread

Back
Top Bottom