p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > Microsoft Office > Access and Access VBA > Access
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.

Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 8th, 2004, 01:15 PM
Registered User
Points: 18, Level: 1
Points: 18, Level: 1 Points: 18, Level: 1 Points: 18, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: London, , United Kingdom.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Validate calculated field in sub form

Hi,

I have a total in the form footer of a sub form which I would like to compare with a value on my main form -- then flash up a simple msgbox if the sub form value is greater than the main form value.

The problem seems to be comparing against a calculated value.

Any help appreciated.

Thanks.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old March 8th, 2004, 01:40 PM
Authorized User
Points: 196, Level: 3
Points: 196, Level: 3 Points: 196, Level: 3 Points: 196, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2004
Location: Edmonton, Alberta, Canada.
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Assuming that the values are displayed in a control like a label or a textbox, you can compare the values or the values of the captions. Most likely you have these figures as the Value property of textboxes. This is the default property so you need to be able to reference the controls by their names.

The bigger question is when do you want this message to display? Your options are likely the afterupdate event of the parent control value, assuming it is entered by a user, or the current event of the parent form. Alternatively, if there are line items that you are adding in the sub form, you may want to use the afterupdate event of the subform. Essentially, you need to choose one or more events that are triggered when the record changes or the values to be compared will change.

Assuming you are calling it from a parent form event, the syntax looks like:

If Me.txtBoxValue < Me.subFormControlName.Form.txtCalculated Then
    MsgBox...
End if

where txtBoxValue is the name of the control on the parent form and subFormControlName is the name of the subform control, not the name of the form embedded as a subform, and txtCalculated is the name of the control containing the calculated value on the subform.

To call it from an event on the subform, the syntax is a bit simpler:

If Me.txtCalculated > Me.Parent.txtBoxValue Then
    MsgBox...
End if


Ciao
Jürgen Welz
Edmonton AB Canada
jwelz@hotmail.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old March 8th, 2004, 01:42 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm not sure if I exactly understand your problem. If you are having trouble figuring out the syntax to address controls on another subform, join the club. But if you want to see at any given time whether one value is greater than another, then I think the simple answer is to create 2 variables in your module [Public intFirstValue as Integer, Public intSecondValue as Integer] and then assign the two numbers you are trying to compare to these variables.

From that point, you need a little procedure that you call whenever you want to compare these numbers:

sub Check Values ()
   If intSecondValue <> intFirstValue then
        msgbox
   end if
end sub

The only problem left is where to put the call, and that involves figuring out an event to stick it in [form open, form change, control before update, etc.].

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old March 12th, 2004, 03:18 PM
Ben Ben is offline
Authorized User
Points: 258, Level: 5
Points: 258, Level: 5 Points: 258, Level: 5 Points: 258, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:If you are having trouble figuring out the syntax to address controls on another subform, join the club.
Enter the below in the ControlSource of a Control on your form:

=[Forms]![Form Name]![SubForm Name].[Form]![SubForm Control Name]

Only thing to remember is the SubForm Name is the name defined for the SubForm Control on your Form, not the name of the SubForm as defined in the database.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #5 (permalink)  
Old March 18th, 2004, 04:26 PM
Friend of Wrox
Points: 9,516, Level: 42
Points: 9,516, Level: 42 Points: 9,516, Level: 42 Points: 9,516, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,060
Thanks: 0
Thanked 10 Times in 10 Posts
Default

I haven't tried this but perhaps Conditional Formatting would work here. If the value in the one field was greater than or equal to the value in another field, then display Red Bold. I am not sure if this will work between subforms and forms, but I do exactly what you are asking on Reports using CF. I know it also works with Forms.

mmcdonal
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Grouping with calculated field in report jack123 Access 3 August 9th, 2007 07:46 AM
How to create a Calculated Field fdtoo SQL Server 2000 0 April 11th, 2006 09:34 PM
Automatically select value from a calculated field jimmy0305 Access 0 June 21st, 2005 11:43 AM
Auto Calculated Field in Access anubhav.kumar Access 1 March 15th, 2005 08:37 AM
how to added a calculated field in pivot table ndenhere BOOK: Access 2003 VBA Programmer's Reference 0 May 27th, 2004 03:45 AM



All times are GMT -4. The time now is 01:55 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc