I have a form and a button and a table with two lists (list1 , list2)
in the form I have text box named text2
when pressing the command button it replaces list1 with text2 value using (replace list1 with thisform.text2.value)
but for list2 I want it to be "alpha" if I wrote number 7009 in text2 and "beta" if I wrote number 7004 in text2
what is the correct way to write the command in the button?
I tried
if thisform.text2.value=7009
replace list2 with "alpha"
else thisform.text.2value=7005
replace list 2 with "beta"
endif
I even tried rewriting the code with and without the "" and it seemed to have bunch of errors without writing it
and when I do write them it just ignores the command and decides to replace list2 with "beta" regardless of the number I wrote
(You started describing your problem with saying list objects on form and then doing replacement on a field called list2. So I would assume your question was not stated correctly and you meant to replace list2 field)
If you want to use if ... endif:
if thisform.text2.value=7009
replace list2 with "alpha"
endif
if thisform.text2.value=7005
replace list2 with "beta"
endif
Or you can use DO case...endcase:
Do case
case thisform.text2.value=7009
replace list2 with "alpha"
case thisform.text2.value=7005
replace list2 with "beta"
endcase
Or you could use iCase():
replace list2 with iCase(;
thisform.text2.value=7009, "alpha",;
thisform.text2.value=7005, "beta")
Note that iCase() version, unlike others, would attempt to do a replace if the value is not 7009 nor 7005. And it would attempt to replace with a NULL. That might cause error if your field is not accepting nulls. It is better to include an "otherwise" value:
replace list2 with iCase(;
thisform.text2.value=7009, "alpha",;
thisform.text2.value=7005, "beta",;
"")