Here's a snapshot of my 'ESTIMATES' form:

What I'm trying to do is this: when a user needs to create a new estimate for someone they believe is an existing client, they can enter a phone number (10 full digits) and/or a partial company name (with a minimum of 4 characters) and when they click on 'FIND' an @XResultSetSearch will be made to another db within the application named 'CLIENTS'.
Here's the programming for the command button:
#include "sbasic_include.sbas"
var rs_key as Int
var vCompany as String
var vTele as String
IF @IsBlank(COMPANYNAME) = 1 AND @IsBlank(TELE) = 1 // both fields are empty.
{
Write("The Company and Telephone fields are blank.")
}
ELSE
{
IF @IsBlank(COMPANYNAME) = 0 AND @IsBlank(TELE) = 1 // COMPANYNAME is not empty, but TELE is empty.
{
IF @LEN(COMPANYNAME) >= 4 // COMPANYNAME is at least four characters long.
{
//Write("You have put in a company name with at least four characters!") /// SEARCH FOR MATCHING COMPANYNAME matches using @XResultSetSearch!
vCompany = "!COMPANYNAME=.." + COMPANYNAME + ".."
rs_key = @XResultSetSearch(@FN, "CLIENTS", SEARCH_MODE_OR, SEARCH_SYNTAX_QA, vCompany)
//Write("Number of XResult Records Found = " + @XResultSetTotal(rs_key))
IF @XResultSetTotal(rs_key) = 1 // Only one record is found.
{
XResultSetCurrentPosition(rs_key, 1) // set our position in the record set.
// WriteLn("Only one matching company found: " + @XResultSetValue(rs_key, "COMPANYNAME"))
//WriteLn("The COMPANYNAME field in this form should be: " + @XResultSetValue(rs_key, "COMPANYNAME"), "The TELE field should be: " + @XResultSetValue(rs_key, "TELE"))
COMPANYNAME = @XResultSetValue(rs_key, "COMPANYNAME")
TELE = @XResultSetValue(rs_key, "TELE")
CUSTNO = @XResultSetValue(rs_key, "CUSTNO")
LNAME = @XResultSetValue(rs_key, "LNAME")
FNAME = @XResultSetValue(rs_key, "FNAME")
MOBILE = @XResultSetValue(rs_key, "MOBILE")
ADDRESS1 = @XResultSetValue(rs_key, "ADDRESS1")
ADDRESS2 = @XResultSetValue(rs_key, "ADDRESS2")
CITY = @XResultSetValue(rs_key, "CITY")
STATE = @XResultSetValue(rs_key, "STATE")
ZIP = @XResultSetValue(rs_key, "ZIP")
FAX = @XResultSetValue(rs_key, "FAX")
REP = @XResultSetValue(rs_key, "REP")
}
}
ELSE
{
Write("You cannot search for a company using fewer than four (4) characters.")
}
}
ELSE
{
IF @IsBlank(COMPANYNAME) = 1 AND @IsBlank(TELE) = 0 // COMPANYNAME blank, TELE is not empty.
{
IF @LEN(@NUM(TELE)) = 10 // 10 digits have been supplied.
{
Write("You have entered 10 digits for the phone number, good job!") /// SEARCH FOR TELE using XResult.
}
ELSE
{
Write("The telephone field must have 10 digits.")
}
}
ELSE
{
IF @IsBlank(COMPANYNAME) = 0 AND @IsBlank(TELE) = 0 // Both fields are filled.
{
IF @LEN(@NUM(TELE)) = 10 AND @LEN(COMPANYNAME) >= 4 // Both fields meet criteria.
{
Write("Hooray! You've input the Company and Tele fields correctly!")
}
ELSE
{
Write("The Telephone field must have exactly 10 digits, and the Company field must have at least 4.")
}
}
}
}
}
To start, I put WriteLn() comments in the code so that I could see that it was reacting properly. Please excuse how spread out my IF/ELSE statements are, I'm very new to this. This code is working when the company field is given input that results in only a single record turning up in the result set. Under that condition I would want Sesame to fill the contact info fields in the ESTIMATES form, but when more than one result turns up (some of our clients have multiple locations, or multiple contacts) I would like the user to be given a popup menu of some kind that would list the result set records, so a choice could be made.
I was thinking if I could loop through the result set and create a string array of values that looked like this:
COMPANYNAME: FNAME LNAME -- TELE
So the user would see:
HappyFun Corp.: John Smith -- 212-555-4444
StifleJoyCo.: Bob Joseph -- 212-444-5555
I could then grab the rightmost 10 characters (the phone number) and use that to indicate what record to finally pull.
Am I making this more complicated than it needs to be, or is there some simple way of doing this?
Any tips, criticisms or ideas would be greatly appreciated.
I feel like a chimpanzee in the Space Shuttle, lol! (twists some dials at random)