Microsoft Access Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft Access Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 29th, 2004, 06:03 PM
tis tis is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 9 tis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Setting condition in report to return control from different source

I am trying to set a condition in a text box so that I can

find the largest value in column (x) and return the value in column (y) on the same row. Thanks for any suggestions.

Thomas

Reply With Quote
  #2  
Old December 29th, 2004, 09:10 PM
lwells lwells is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Sep 2004
Posts: 632 lwells User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 21 h 59 m 38 sec
Reputation Power: 5
Hi Thomas,

There are probably several ways you can do this, but the method that I use is creating a recordset using the DMax function and then retrieving the value from the specific field that I want.

You can try this code behind a command button that will put the value of column Y into a text box after finding the max value of column X.

Dim db As DAO.Database
Dim rs As Recordset
Dim strField As String
Dim strSQL As String
Dim strItem As String
strItem = DMax("[ColumnX]", "TableName")
strSQL = "SELECT TableName.* " & _
"FROM TableName " & _
"WHERE [ColumnX] =" & strItem
Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL, dbOpenSnapshot)

With rs
strField = rs!ColumnY.Value
End With

txtField = strField

Just substitute the table and field names as well as your text box names in place of the items in bold and italics.

lwells

Reply With Quote
  #3  
Old December 30th, 2004, 10:27 AM
tis tis is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 9 tis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks for the info but I will need a little more details. I have yet to use a command button. Where do you input this code and where do you substitute the text box?

Reply With Quote
  #4  
Old December 30th, 2004, 01:10 PM
lwells lwells is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Sep 2004
Posts: 632 lwells User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 21 h 59 m 38 sec
Reputation Power: 5
The code was just an example of some code that could be used in your application. Can you possibly explain what exactly you are wanting to do and I will modify the code for you. Your original post said you were trying to set a condition for a text box. What did you mean by that?

lwells

Reply With Quote
  #5  
Old December 30th, 2004, 02:29 PM
tis tis is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 9 tis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
In the report header I have Profit$ and Salesperson. The detail section contains all the related info of Profit$ and corresponding salesperson. The footer contains a summary: Total Sales, Total Profit$, and Profit%. I would like the Salesperson with the highest Profit$ to be in this summary with their Profit$ figure.
I really appreciate you help on this.

Reply With Quote
  #6  
Old December 30th, 2004, 02:59 PM
MrBullwinkle MrBullwinkle is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Wild and Wonderful, West Virginia
Posts: 27 MrBullwinkle User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to MrBullwinkle Send a message via AIM to MrBullwinkle Send a message via MSN to MrBullwinkle Send a message via Yahoo to MrBullwinkle
What you're wanting to do can't be done directly in a text box. You have to incorporant lwells code or link the cell to a query. If you used a query it would do it automatically, vs a command button.

Command buttons are the things you click on do make something happen. such as "Ok", "Cancel", "Clear"

Reply With Quote
  #7  
Old December 30th, 2004, 03:54 PM
lwells lwells is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Sep 2004
Posts: 632 lwells User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 21 h 59 m 38 sec
Reputation Power: 5
Thomas,

In this case, in your summary section of your report, place an unbound text box to display the Sales Person name and use the code that I gave you in the On Activate event of your report. You can also place an unbound text box to display the profit amount and use the Dmax function to get that value as well.

Or as MrBullwinkle suggested, create a query to obtain the same information for your report without writing the code.

lwells

Reply With Quote
  #8  
Old December 30th, 2004, 04:23 PM
tis tis is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 9 tis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Do I need to make more than 1 query to get this info? If I make another query that adds all the seperate Profit$ with corresponding salespersons I am back with the same info I have on the report.

Reply With Quote
  #9  
Old December 30th, 2004, 09:26 PM
lwells lwells is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Sep 2004
Posts: 632 lwells User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 21 h 59 m 38 sec
Reputation Power: 5
You only need one query to get the max record(s) to display (separate from the query used in your report). Just set the criteria using the DMax function in the criteria grid under the field for Profit$. This will then give you the query showing the record(s) that you are looking for. In your report footer, arrange your text boxes where you want them, and then for the control source for each text box use the DLookup function to find the Profit$ and Sales Person field from the query.

The syntax for your control source of the text boxes would be:
=DLookup("[SalesPerson]","NameofQuery") and =DLookup("[Profit$]","NameofQuery")

You may have to plan on what to do if two different Sales people have identical Profit$ and maybe come up with some criteria to act as the tie breaker.

Will that help any?
lwells

Reply With Quote
  #10  
Old January 3rd, 2005, 09:47 AM
tis tis is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 9 tis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
No quite but thanks for all your help. I keep getting this message when I try to run the qry

"The expression you entered contains invalid syntax
You may have entered an operand without an operator"

and it highlights the second Dim in your code.

Thomas

Reply With Quote
  #11  
Old January 3rd, 2005, 01:57 PM
MrBullwinkle MrBullwinkle is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Wild and Wonderful, West Virginia
Posts: 27 MrBullwinkle User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to MrBullwinkle Send a message via AIM to MrBullwinkle Send a message via MSN to MrBullwinkle Send a message via Yahoo to MrBullwinkle
You probably don't have the recordset references loaded. I'm not exactly sure what ones they are.

Reply With Quote
  #12  
Old January 3rd, 2005, 06:44 PM
lwells lwells is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Sep 2004
Posts: 632 lwells User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 21 h 59 m 38 sec
Reputation Power: 5
Add the references to the DAO object library. In your code window go to Tools/References and scroll down until you find the MicroSoft 3.XX Object Library. Depending on your version the actual number will vary.

lwells

Reply With Quote
  #13  
Old January 4th, 2005, 02:58 PM
krulin23 krulin23 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Chicago
Posts: 10 krulin23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
sometimes you would have to prioritize the references in order for them to work,
i think its microsoft DAO 3.6 object library,

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft Access Development > Condition in report


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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 On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT