Hot Topic (More than 10 Replies) How can you xlookup data using more than 1 key LE? (Read 1956 times)
Steve_in_Texas
Senior Member
*****
Offline


No personal text

Posts: 893
Location: San Antonio
Joined: Feb 21st, 2004
How can you xlookup data using more than 1 key LE?
Apr 27th, 2004 at 3:44am
Print Post Print Post  
Can this be done?

I want to 'xlookup' search through the LineItems database and find all items sold to a particular customer (Key field #1 =Last Name) AND show only items that have a 'balance due' (key field #2 = "balance due")

Is there a way to filter the xlookup results so that only "items with a balance due" will be revealed?

Thanks,

Steve in Texas
  
Back to top
IP Logged
 
Justin_ICC
Junior Member
**
Offline



Posts: 95
Joined: Feb 5th, 2004
Re: How can you xlookup data using more than 1 key
Reply #1 - Apr 29th, 2004 at 4:00pm
Print Post Print Post  
One way you could accomplish this is to create a subform with all the line items (if you don't want it to be shown make it invisible - haven't tested this part yet).

you can then set up some programming to loop through each item in the list and get the information you want form it and display it to the user.

If you want more detailed examples I'll dig up the programming to loop through the line items.
  
Back to top
 
IP Logged
 
Steve_in_Texas
Senior Member
*****
Offline


No personal text

Posts: 893
Location: San Antonio
Joined: Feb 21st, 2004
Re: How can you xlookup data using more than 1 key
Reply #2 - Apr 29th, 2004 at 4:07pm
Print Post Print Post  
Justin, nice idea. I never thought of making a subform invisible.

This may be exactly what i need. Also, skimming over the May issue of Inside Sesame, I may be able to acomplish "selective xlookups" by buildling 'picklists of sorts' that only show the particular records requested.

However, your idea sounds much easier.

Thanks,
Steve in Texas
  
Back to top
IP Logged
 
Justin_ICC
Junior Member
**
Offline



Posts: 95
Joined: Feb 5th, 2004
Re: How can you xlookup data using more than 1 key
Reply #3 - Apr 29th, 2004 at 5:06pm
Print Post Print Post  
Glad to help I like thinking outside of the box. Its not that i'm claustrophobic or anything but its just so much more interesting Wink It just sort of works out that i'm working on something kind of similar currently.

  
Back to top
 
IP Logged
 
Steve_in_Texas
Senior Member
*****
Offline


No personal text

Posts: 893
Location: San Antonio
Joined: Feb 21st, 2004
Re: How can you xlookup data using more than 1 key
Reply #4 - May 10th, 2004 at 2:28am
Print Post Print Post  
Justin, or anyone else,

In order for programming to loop through the Lineitems database, does the LineItems database need to be on the form (either as a subform or on the main form, itself)?

I'd like to use programming that can loop through a database that is not in my form.

Thanks for any assistance.

Steve in Texas
  
Back to top
IP Logged
 
Justin_ICC
Junior Member
**
Offline



Posts: 95
Joined: Feb 5th, 2004
Re: How can you xlookup data using more than 1 key
Reply #5 - May 10th, 2004 at 11:33am
Print Post Print Post  
As far as I can tell you can only perform looping on subforms. There is no way that i've seen to loop on a database when it is not a subform.

Justin
  
Back to top
 
IP Logged
 
billgordon
Junior Member
**
Offline


No personal text

Posts: 61
Joined: Dec 31st, 2003
Re: How can you xlookup data using more than 1 key
Reply #6 - May 10th, 2004 at 12:00pm
Print Post Print Post  
Justin,

could you please post  a code example of how to loop through a subform to filter the data.

This will be helpfull to many. Thank you.
  
Back to top
 
IP Logged
 
Justin_ICC
Junior Member
**
Offline



Posts: 95
Joined: Feb 5th, 2004
Re: How can you xlookup data using more than 1 key
Reply #7 - May 10th, 2004 at 1:56pm
Print Post Print Post  
Here is an example that loops through a subform containing payments and totals all the payments. You can do anything you want with the data (post messages to a multi-line text box that is unbound, etc.)

If you have any questions let me know. All variables start with a v all other variable-type objects in the code are layout elements.


Code
Select All
////////////////////////////////////////////////////////////////////////////////
// Loop through a subform and total all payments
////////////////////////////////////////////////////////////////////////////////

// Declare Variables
var vCnt as Int			// total number of records in subtable.
var vLoop As Int		// Counter to be used to increment from one record to the next in the subtable
var vMyTotalHere as Double	// total of payments made to us
var vMyTotalDIR as Double	// total of payments made to client
var vMyTotalCHere as Double	// commission on payments made to us
var vMyTotalCDIR as Double	// commision on payments made to client
var vPayDate as Date		// Date of Payment

///////////////////////////////////////////////////////////////////////////////
//  Calculate the totals of payments and recalculate the outstanding balance
///////////////////////////////////////////////////////////////////////////////

// initialize payments sum
vMyTotalHere = 0;
vMyTotalDIR  = 0;
vMyTotalCHere = 0;
vMyTotalCDIR  = 0;

// retrieve number of records
vCnt = @FormResultSetTotal("Payments Table");

// verify if there are any new payments
if vCnt <> PrevPayments: then
{	// if there are new payments update the payment counter (refreshed on form load)
	PrevPayments: = vCnt;

	// start at the first payment
	vLoop = 1;

	// loop through all payments
	while vLoop <= vCnt
	{

		// get the sum of the payments
		vMyTotalHere = vMyTotalHere+@ToMoney(@FormFieldValue("Payments Table","PmtHere", vLoop));
		vMyTotalDIR = vMyTotalDIR+@ToMoney(@FormFieldValue("Payments Table","PmtDIR", vLoop));
		vMyTotalCHere = vMyTotalCHere+@ToMoney(@FormFieldValue("Payments Table","ComHere", vLoop));
		vMyTotalCDIR = vMyTotalCDIR+@ToMoney(@FormFieldValue("Payments Table","ComDIR", vLoop));

		// get the date of each payment
		vPayDate = @ToDate(@FormFieldValue("Payments Table","PmtDate",vLoop));

		// move to next payment
		vLoop = vLoop + 1;
	}

	// Display totals in summary boxes.
	Payments Here:    = vMyTotalHere
	Payments DIR:     = vMyTotalDIR
	Total Payments:   = vMyTotalHere + vMyTotalDIR
	Commission Here:  = vMyTotalCHere
	Commission DIR:   = vMyTotalCDIR
	Total Commission: = vMyTotalCHere + vMyTotalCDIR
}
 

  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: How can you xlookup data using more than 1 key
Reply #8 - May 10th, 2004 at 2:14pm
Print Post Print Post  
Quote:
As far as I can tell you can only perform looping on subforms. There is no way that i've seen to loop on a database when it is not a subform.

Justin


You can use @FormFieldValue and @FormResultSetTotal on any open form. For example, the following code works in the Customers.db application which is entirely flat and only contains the single database and form:

Code
Select All
var loop as int
var cnt as int
var val as string

    cnt = @FormResultSetTotal("Main Form")
    loop = 1
    while(loop <= cnt)
    {
	    val = @FormFieldValue("Main Form", "City", loop)
	    writeln(val)
	    loop = loop + 1
    }
 

  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Justin_ICC
Junior Member
**
Offline



Posts: 95
Joined: Feb 5th, 2004
Re: How can you xlookup data using more than 1 key
Reply #9 - May 10th, 2004 at 2:21pm
Print Post Print Post  
Quote:
You can use @FormFieldValue and @FormResultSetTotal on any open form. For example, the following code works in the Customers.db application which is entirely flat and only contains the single database and form


Hammer,

If a user has the form in question open will it start cycling through it or will it leave it at the point they had it? I was under the impression that this is waht happens. Also what would happen if that form wasn't open?

Thanks,
Justin
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: How can you xlookup data using more than 1 key
Reply #10 - May 10th, 2004 at 2:28pm
Print Post Print Post  
Quote:
Hammer,


I'm Mark (The Cow)

Quote:
If a user has the form in question open will it start cycling through it or will it leave it at the point they had it? I was under the impression that this is waht happens. Also what would happen if that form wasn't open?

It will cyle through the specified entries in the result set, then return to the user to the entry they were on when it started. If the form isn't open it wil fail - but then you won't be getting in the loop because @FormResultSetTotal will return -1.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Justin_ICC
Junior Member
**
Offline



Posts: 95
Joined: Feb 5th, 2004
Re: How can you xlookup data using more than 1 key
Reply #11 - May 10th, 2004 at 2:35pm
Print Post Print Post  
Oops lol sorry Mark, I was thinking about the e-mail notification when i started the reply.

I was wondering if that is the case I have a theory I'd like to run by. Our database has accounts and payments, I would like to have the program cycle through all the current payments on the account, sum them up before it calculates the comission on the next payment would it be possible to do this using that code you suggested. The reason for this is we have some sliding scale comission rates and it won't calculate them correctly unless it knows what payments have been made first. I want this code to execute on add payment - i know i'll have more difficult later one when they are correcting a payment but one step at a time.

If it will let me loop on the active form I also have one other question. Does it automatically commit existing changes on the form before it starts flipping through them or does it record which changes there are and then restore the form "as is" or does it discard the change?

Justin
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: How can you xlookup data using more than 1 key
Reply #12 - May 10th, 2004 at 3:05pm
Print Post Print Post  
Quote:
Does it automatically commit existing changes on the form before it starts flipping through them or does it record which changes there are and then restore the form "as is" or does it discard the change?


It is about the same as hitting F10. So, it will commit the "starting" record and any changes made along the way.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Justin_ICC
Junior Member
**
Offline



Posts: 95
Joined: Feb 5th, 2004
Re: How can you xlookup data using more than 1 key
Reply #13 - May 10th, 2004 at 3:18pm
Print Post Print Post  
I was just thinking would it be possible to use something like @userselect - the same command to populate a popup window to maybe pull up certain pieces of information?

Justin
  
Back to top
 
IP Logged