Normal Topic Creating unique Subrecords from Main Form (Read 571 times)
Amor
Full Member
Members
***
Offline


No personal text

Posts: 366
Location: Germany
Joined: Feb 7th, 2004
Creating unique Subrecords from Main Form
Apr 20th, 2009 at 12:08pm
Print Post Print Post  
Hello!

I add articles from a Main Form  to a Subform .
However, every added article must be only once occur in the Subreform (or the ItemCode).
I'd like before a new inserted a record, i would informed ob this Article has been recorded in the Subform or not.
How can I achieve this?

I would like to thank you for any support.
  

Dr. med. Amor Belhareth&&Medizin Labor &&Germany
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Creating unique Subrecords from Main Form
Reply #1 - Apr 20th, 2009 at 2:19pm
Print Post Print Post  
Here's a generic function that should do it for you. It may need some adjustment if you are comparing numbers instead of strings.

Code
Select All
// Checks all subform records to see if any subrecord exists with
// the specified value in the specified field.
// Arguments:
// aCheckVal - Value to look for
// aForm - Name of subform
// aField - Name of field to check
// Returns True if a matching record is found

FUNCTION ExistsInSubform(aCheckVal as String, aForm as String, aField as String) as Boolean
var vRet as Boolean
var vLoop as Int
var vCount as Int
var vVal as String

	vRet = False
	vCount = @FormResultSetTotal(aForm)
	vLoop = 1
	While (vLoop <= vCount) And (vRet = False)
	{
		vVal = @FormFieldValue(aForm, aField, vLoop)
		If vVal = aCheckVal
		{
			vRet = True
		}
		vLoop = vLoop + 1
	}
	Return vRet

END FUNCTION

// Example of use to check if the value entered in the NewItemCode element appears in
// any record in the Articles subform in the element called ItemCode.

	If ExistsInSubform(NewItemCode, "Articles", "ItemCode")
	{
		@MsgBox("Error: Record alread exists.")
	}
	Else
	{
		// Do add record
	}

 

  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Amor
Full Member
Members
***
Offline


No personal text

Posts: 366
Location: Germany
Joined: Feb 7th, 2004
Re: Creating unique Subrecords from Main Form
Reply #2 - Apr 20th, 2009 at 4:33pm
Print Post Print Post  
And straightaway tasted works!
It is simply amazing as Erika Code writes: compact and efficient! I hope a day to write so refined Code.

Thank you, and again thank Erika.
  

Dr. med. Amor Belhareth&&Medizin Labor &&Germany
Back to top
 
IP Logged