Hot Topic (More than 10 Replies) SU - Speedy Unique (Read 1878 times)
UPaul42
Junior Member
Members
**
Offline


been a Q&A user/programmer
since version 2.0

Posts: 57
Location: Broad Brook CT
Joined: Jul 23rd, 2003
SU - Speedy Unique
Nov 17th, 2005 at 3:15am
Print Post Print Post  
I am using the following code.

This is On-Element Exit for the LE "Hebrew"
--------------------
var vHebrew as String

If @Add then

{

If vHebrew = @XLU(@FN, "Hebrew", "Hachibur!Hebrew", "Hebrew")

{
NotifyForm(1)
vHebrew = @XLU(@FN, "Hebrew", "Hachibur!Hebrew", "Hebrew")
@MsgBox("This Entry matches an existing entry", vHebrew, "Please modify this code OR exit without saving.")
}

Else

NotifyForm(0)

}
--------------------
It doesn't work as intended. It is expected to show duplicate data being entered with a warning. It warns on all entries in this element whether they exist or not.

Hachibur is the Form
Hebrew is a LE that contains the new entry and is the Field with the existing data (TEXT)

  

&&http://www.lantica.com/images/sespro_badges/sespro3.gif&&Paul Anderson&&President&&Systems-Consulting&&89 Main Street, Broad Brook CT 06016&&(860) 627-5393&&Sales@Systems-Consulting.com
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: SU - Speedy Unique
Reply #1 - Nov 17th, 2005 at 4:01am
Print Post Print Post  
For starters, you are using the literal value of "Hebrew" as your key value. If you are trying to use the value that is in the Hebrew LE as your key, there should be no quotes around it. Try this...
@XLU(@FN, Hebrew, "Hachibur!Hebrew", "Hebrew")
rather than this...
@XLU(@FN, "Hebrew", "Hachibur!Hebrew", "Hebrew")

Another thing I see right away is, you are using vHebrew to compare with the result of the xlookup, but you have not yet given it a value. Since vHebrew has no value, and xlooup did not find the literal value "Hebrew" in the Hebrew LE, you ended up with a TRUE condition, which then activated the section of code that includes @MsgBox().

You also might want to consider using @IsNew rather than @Add, because someone could be in update mode and still be adding records via extend mode. You can read more about this in the Q&A note on page 183 of the Programming Guide, just under the @IsNew reference/description.

  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
UPaul42
Junior Member
Members
**
Offline


been a Q&A user/programmer
since version 2.0

Posts: 57
Location: Broad Brook CT
Joined: Jul 23rd, 2003
Re: SU - Speedy Unique
Reply #2 - Nov 17th, 2005 at 1:23pm
Print Post Print Post  
Thanks Carl.

Here's the final working code.

------------------
var vHebrew as String

vHebrew = Hebrew

If @IsNew then

{

If vHebrew = @XLU(@FN, Hebrew, "Hachibur!Hebrew", "Hebrew") then

     {
     NotifyForm(1)
     @MsgBox("This Entry matches an existing entry", vHebrew, "Please modify this code OR exit without saving.")
     }
}


Else

{
NotifyForm(0)

}

------------------
Grin
  

&&http://www.lantica.com/images/sespro_badges/sespro3.gif&&Paul Anderson&&President&&Systems-Consulting&&89 Main Street, Broad Brook CT 06016&&(860) 627-5393&&Sales@Systems-Consulting.com
Back to top
IP Logged
 
Don Haley
Member
*
Offline


No personal text

Posts: 38
Location: Plymouth, Devon, UK
Joined: Jan 23rd, 2004
Re: SU - Speedy Unique
Reply #3 - Jan 4th, 2006 at 5:28pm
Print Post Print Post  
Hello All

I have an element named Part Number, which I wish to be unique. Thanks to Carl & Paul with an earlier posting I have adapted Paul's code to suit my needs and added the first few lines to allow for blank records.  What I wish to do is to make it impossible for anyone to alter an existing record and have the same part number twice.  I have tried adding @ Modified (as shown in red in the code) but this fires whenever anything in the form is changed.  So the question is "is it possible to program the form  to stop anyone changing the part number to an existing part number"?

Thankyou

Don

var vPart Number as String

vPart Number = Part Number

If Part Number = "" Then

{

ThrowFocus (Description)

}

Else

{


If@IsNew OR @Modified then

{

If vPart Number = @XLU(@FN, Part Number, "Stock!Part Number", "Part Number")then

     {
     NotifyForm(1)
     @MsgBox("This Entry matches an existing entry", vPart Number,"Please modify this code OR exit without saving.")
     }
}

Else

{
NotifyForm(0)
}
}
  
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: SU - Speedy Unique
Reply #4 - Jan 4th, 2006 at 6:03pm
Print Post Print Post  
Hello Don,

In Global Code declare a Static String

Code
Select All
Stat gsPartNumber as String

gsPartNumber = "" 



Then in the Form On Form Entry event set the Global Static to be the current part number

Code
Select All
gsPartNumber = Part Number 



Then in your current event goes code that will look something like this

Code
Select All
var vPartNumber as String

vPartNumber = Part Number

If Part Number = "" Then
{
	ThrowFocus (Description)
}
Else
{
	NotifyForm(0)
	If ((@IsNew) OR (vPartNumber <> gsPartNumber)) Then
	{
		If vPartNumber = @XLU(@FN, Part Number, "Stock!Part Number", "Part Number") Then
		{
			NotifyForm(1)
			@MsgBox("This Entry matches an existing entry", vPartNumber,"Please modify this code OR exit without saving.")
		}
	}
} 



What it does it it stores the current Part number when you enter the record and then in the on exit event of the Part Number element it checks to see if it has changed from what it originally was. This is just a rough draft of the code but should get you started in the right direction.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Don Haley
Member
*
Offline


No personal text

Posts: 38
Location: Plymouth, Devon, UK
Joined: Jan 23rd, 2004
Re: SU - Speedy Unique
Reply #5 - Jan 4th, 2006 at 6:14pm
Print Post Print Post  
Hello Ray

Thanks very much.  I will give it a try.

Don
  
Back to top
 
IP Logged
 
Don Haley
Member
*
Offline


No personal text

Posts: 38
Location: Plymouth, Devon, UK
Joined: Jan 23rd, 2004
Re: SU - Speedy Unique
Reply #6 - Jan 4th, 2006 at 6:53pm
Print Post Print Post  
Hello Ray

That works a treat. Thank you very much.

Don
  
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: SU - Speedy Unique
Reply #7 - Jan 4th, 2006 at 7:03pm
Print Post Print Post  
Hello Don,

You are welcome.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: SU - Speedy Unique
Reply #8 - Jan 11th, 2006 at 3:01pm
Print Post Print Post  
I'm using a variation of some of the code above to test whether a new employee record matches a record that already exists.  On my employee form I have LE's "LastName", "FirstName" and "FullName".

On-element-exit for Firstname does this:
Code
Select All
// Creates FullName from both name parts

If @IsBlank(FullName) or not FullName=(Firstname+" "+Lastname) then
	{
	FullName=(Firstname+" "+Lastname)
	ThrowFocus(Address)
	}
Else
	ThrowFocus(Address) 



On-element-change for FullName does this:
Code
Select All
// Checks to see if employee already exists

var vFullName as String

vFullName = FullName

If @IsNew then

	{
	 If vFullName = @XLU(@FN, FullName, "Employee!FullName", "FullName") then
		 {
		NotifyForm(1) // Prevent save
		@MsgBox("This Employee record already exists", FullName, "Please modify this record OR exit without saving.")
		Throwfocus(LastName)
		}
	}
Else
	{
	NotifyForm(0) //Allow save
	Throwfocus(Address)
	 } 



This is working well and doing what I want, making sure that FullName is a unique value.  However when the error condition occurs (that is, when someone generates a FullName that already exists) it takes 3 clicks of the "OK" message box box to acknowledge the problem and return to the form.

Am I doing something wrong with ThrowFocus that might be causing this?  Or is there some other error I can't see?
  

**
Captain Infinity
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: SU - Speedy Unique
Reply #9 - Jan 11th, 2006 at 3:30pm
Print Post Print Post  
Hello Scott,

Yes it is possible that the ThrowFocus is causing the programming to run again. Try removing the ThrowFocus calls and let me know if you are left with only one warning.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: SU - Speedy Unique
Reply #10 - Jan 11th, 2006 at 3:36pm
Print Post Print Post  
Hi Ray!

Removing the ThrowFocus calls from the FirstName element cuts the warnings down to two.  Removing them from both elements cuts them down to just one.

Is there a better way to send my user back to LastName if the duplication condition occurs?  Not that it's really a problem, because if NotifyForm(1) is working like it should they can't save the record duplication occurs anyway.  But I haven't tested that yet.
  

**
Captain Infinity
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: SU - Speedy Unique
Reply #11 - Jan 11th, 2006 at 3:52pm
Print Post Print Post  
OK, I've removed all ThrowFocus calls.  Only one warning to click away, yay!

BUT!  When I correct the firstname or lastname fields after the error, which generates a new FullName, I still cannot Save.  Seems like the "nosave" condition is being persistent.

So I tried initializing the value, with this:
On-element-change for FullName
Code
Select All
// Checks to see if employee already exists

var vFullName as String

vFullName = FullName

If @IsNew then

	{
	NotifyForm(0)
 	If vFullName = @XLU(@FN, FullName, "Employee!FullName", "FullName") then
 		{
		NotifyForm(1) // Prevent save
		@MsgBox("This Employee record already exists", FullName, "Please modify this record OR exit without saving.")
		}
	}
Else
	{
	NotifyForm(0) //Allow save
	ThrowFocus(Address)
 	} 


But it doesn't work. Sad
  

**
Captain Infinity
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: SU - Speedy Unique
Reply #12 - Jan 11th, 2006 at 3:56pm
Print Post Print Post  
Please ignore my last message.  I was doing something really stupid which I'm too embarrased to describe.  It's all working now. 

Still would be nice to toss the User into LastName when the duplication occurs, though.
  

**
Captain Infinity
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: SU - Speedy Unique
Reply #13 - Jan 11th, 2006 at 4:20pm
Print Post Print Post  
Hello Scott,

Well you can put back in the ThrowFocus() to the Last Name element. Then have a look at your code and see what events that ThrowFocus() is causing to run and see why they are causing the On Element Change event of the Full Name element to run again.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: SU - Speedy Unique
Reply #14 - Jan 11th, 2006 at 4:41pm
Print Post Print Post  
This requires 2 clicks to acknowledge:
Code
Select All
// Checks to see if employee already exists

var vFullName as String

vFullName = FullName

NotifyForm(0) // Initialize save state

If @IsNew then
 	{
 	If vFullName = @XLU(@FN, FullName, "Employee!FullName", "FullName") then
 		{
		NotifyForm(1) // Prevent save
		@MsgBox("This Employee record already exists", FullName, "Please modify this record OR exit without saving.")
		ThrowFocus(LastName)
		}
	}
Else
	{
	NotifyForm(0) //Allow save
	ThrowFocus(Address)
 	} 



It must have something to do with the on-element-exit event of Firstname, which is what sets off this event if FullName has changed.  I have no programming in LastName.

So the sequence of events is:
* User exits FirstName, FullName is generated
* If FullName matches existing record: saving is initialized, message box comes up, Saving is disallowed.
   * Click to acknowledge
   * (Something happens that requires another click)
   * Message box closes, focus is thrown to LastName
* If FullName is unique or changed back to unique: saving is allowed, focus is thrown to address

It's no big deal, really, at this point...the determination of unique value is working properly and I'm sure the scenario is remote in any case, and since saving is turned off it really doesn't matter where the user goes next because they have to change either the firstname or last name anyway.

Thanks for your help, Ray.
  

**
Captain Infinity
Back to top
IP Logged