Things are almost working, but for one problem. I have a test table called "Junk" with a character field "Anothername." I am looking up names in another table ("names") using a field "Reversenam." This script is attached to the CanWriteField field-rule event for "Anothername."
The idea here is to type in a few letters and look up in "names" for any items that match. If there are none, the write is cancelled. If there is only one match, that name is simply assigned to FoundItem. If there is more than one match, the form "NameLook" is called as a dialog, which displays the query selected records in a browse item and sets the global variable "FoundItem" on exit according to the selected record.
So far so good. Now I want to assign FoundItem to A_FIELD_VALUE. Notice that this is possible before calling the dialog, but after the dialog is closed, setting A_FIELD_VALUE causes the program to crash (i.e. stop responding).
Why? Is there a workaround?
--------------
'Set two global variables
'
SearchText = A_FIELD_VALUE
FoundItem = Junk->Anothername
'Run rest of script only if user has changed the value in Anothername
'
IF SearchText FoundItem THEN
'Select records which begin with SearchText
'
filter = "LEFT(Reversenam," + LTRIM(STR(LEN(SearchText))) + ") = " + chr(34) + SearchText + chr(34)
trace.writeln(filter)
tbl = table.open("names")
query.filter = filter
query.order = "Reversenam"
indx = tbl.query_create()
'Find how many records satisfy the query
'
count = indx.records_get()
FoundItem = tbl.Reversenam
tbl.close()
trace.writeln("Count: " + str(count))
****This instance of setting A_FIELD_VALUE works; however FoundItem contains only the first matching record
A_FIELD_VALUE = FoundItem
'Depending on how many records found
IF count = 0 THEN
FoundItem = ""
cancel()
ELSEIF count > 1 THEN
:form.dialog("NameLook")
END IF
trace.writeln("F: " + FoundItem)
****This instance of setting A_FIELD_VALUE causes a crash if count is > 1 (that is, the dialog has been invoked)
A_FIELD_VALUE = FoundItem
END IF
The idea here is to type in a few letters and look up in "names" for any items that match. If there are none, the write is cancelled. If there is only one match, that name is simply assigned to FoundItem. If there is more than one match, the form "NameLook" is called as a dialog, which displays the query selected records in a browse item and sets the global variable "FoundItem" on exit according to the selected record.
So far so good. Now I want to assign FoundItem to A_FIELD_VALUE. Notice that this is possible before calling the dialog, but after the dialog is closed, setting A_FIELD_VALUE causes the program to crash (i.e. stop responding).
Why? Is there a workaround?
--------------
'Set two global variables
'
SearchText = A_FIELD_VALUE
FoundItem = Junk->Anothername
'Run rest of script only if user has changed the value in Anothername
'
IF SearchText FoundItem THEN
'Select records which begin with SearchText
'
filter = "LEFT(Reversenam," + LTRIM(STR(LEN(SearchText))) + ") = " + chr(34) + SearchText + chr(34)
trace.writeln(filter)
tbl = table.open("names")
query.filter = filter
query.order = "Reversenam"
indx = tbl.query_create()
'Find how many records satisfy the query
'
count = indx.records_get()
FoundItem = tbl.Reversenam
tbl.close()
trace.writeln("Count: " + str(count))
****This instance of setting A_FIELD_VALUE works; however FoundItem contains only the first matching record
A_FIELD_VALUE = FoundItem
'Depending on how many records found
IF count = 0 THEN
FoundItem = ""
cancel()
ELSEIF count > 1 THEN
:form.dialog("NameLook")
END IF
trace.writeln("F: " + FoundItem)
****This instance of setting A_FIELD_VALUE causes a crash if count is > 1 (that is, the dialog has been invoked)
A_FIELD_VALUE = FoundItem
END IF
Comment