-
Oct 22nd, 2017, 11:13 AM
#1
Thread Starter
Enjoy the moment
[RESOLVED] how can i know which customer is most profit in my business
hey
i have a table called Customers
there are 2 fields
FullName
TotalPAyments
how can i know which customer is must profit to my business
and display it in a listview or msgbox
e.x
salsa 32000
mambo 89520
david 12300
regards
salsa31
-
Oct 22nd, 2017, 11:50 AM
#2
Re: how can i know which customer is most profit in my business
Salsa
Maybe something like this
Code:
'
Dim maxProfit As Long
Dim maxName As String
'
maxProfit = 0
rsCustomers.MoveFirst
Do
If rsCustomers.EOF() Then
Exit Do
Else
vprof = rsCustomers("Fullname")
vname = rsCustomers("TotalPayments")
If vprof > maxProfit Then
maxProfit = vprof
maxName = vname
End If
End If
rsCustomers.MoveNext
Loop
'
MsgBox maxName & " " & Trim(maxProfit)
'
Note: I have not tested this.
HTH
Spoo
Last edited by Spooman; Oct 22nd, 2017 at 11:54 AM.
-
Oct 22nd, 2017, 11:39 PM
#3
Thread Starter
Enjoy the moment
Re: how can i know which customer is most profit in my business
Maybe something like this
hey spoo
tried to play with your code
still cant figure it out :/
-
Oct 22nd, 2017, 11:58 PM
#4
Re: how can i know which customer is most profit in my business
If you have a table with those fields you can simply sort the data as part of your query
If you want them all from highest to lowest then
Code:
Select FullName, TotalPAyments from Customers order by TotalPAyments DESC
If you only want the one then
Code:
Select Top 1 FullName, TotalPAyments from Customers order by TotalPAyments DESC
-
Oct 23rd, 2017, 02:19 AM
#5
Thread Starter
Enjoy the moment
Re: how can i know which customer is most profit in my business
so simple
tnk you sir
-
Oct 23rd, 2017, 04:30 AM
#6
Re: [RESOLVED] how can i know which customer is most profit in my business
Salsa
Glad DM's approach worked for you .. so simple, indeed.
FWIW, my approach was a brute force one (SELECT didn't occur to me).
- rsCustomers represented your table
- the concept was to loop through all records to find the record with the maximum profit (ie, largest TotalPayments)
- MoveFirst sets the pointer to the first record
- maxProfit is set to 0 to be the lowest value
- then the loop is entered
- if the current record's profit (vprofit) is larger than the max so for
- maxProfit is updated
- maxName is also updated .. ie, the Customer associated with that profit
- MoveNext sets pointer to the next record
- when the last record is encountered (EOF), the loop is exited.
- the results are then posted in the MsgBox
My terminology may have been a bit confusing ...
- maxProfit vs TotalPaymemts,
- maxName vs Customer
... but I hope that explains the basic concept.
Nonetheless, DM's approach is superior.
Spoo
Last edited by Spooman; Oct 23rd, 2017 at 04:45 AM.
-
Oct 23rd, 2017, 08:04 AM
#7
Re: [RESOLVED] how can i know which customer is most profit in my business
Q) What is profit ?
A) a financial gain, especially the difference between the amount earned and the amount spent in buying, operating, or producing something.
do not put off till tomorrow what you can put off forever
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|