我给一段我的"添加/保存"按钮的完整代码给你,不过我的功能和你的不一样,我是先清空,然后再输入数据,再点"保存",就可以保存数据了.
首先设置这个command的caption为"添加"
command1 click事件中这样写的:
IF this.Caption ='添加'
this.Caption='保存'
fOR i=1 to 3
mytext="text"+ALLTRIM(STR(i))
thisform.&mytext..readonly=.f.&&由于在表单初始化时,使这样控件都是只读的,现在使只读属性为假
endfor
thisform.text1.text1.Value='' &&清空(我的text是一个事先做好的text类,所以每个前面都有text)
thisform.text2.text1.Value=''
thisform.text3.text1.Value=''
thisform.save1.command3.Enabled =.f. &&修改按钮不可用
thisform.save1.command2.Enabled =.f. &&删除按钮不可用
thisform.pointer1.command1.Enabled=.f. &&指针按钮不可用
thisform.pointer1.command2.Enabled=.f. &&指针按钮不可用
thisform.pointer1.command3.Enabled=.f. &&指针按钮不可用
thisform.pointer1.command4.Enabled=.f. &&指针按钮不可用
thisform.text1.text1.setfocus
ELSE
lsname=ALLTRIM(thisform.text1.text1.Value )
lscusname=ALLTRIM(thisform.text2.text1.Value )
lsphone=ALLTRIM(thisform.text3.text1.Value)
IF EMPTY(lsname)
MESSAGEBOX("输入的信息不完整,药店名称不能为空",16,'系统提示')
thisform.text1.text1.setfocus
else
INSERT into drugstore(storename,cusname,phone) values(lsname,lscusname,lsphone)
MESSAGEBOX('数据添加成功',48,'操作成功')
thisform.pointer1.command1.Enabled=.t.
thisform.pointer1.command2.Enabled=.t.
thisform.pointer1.command3.Enabled=.t.
thisform.pointer1.command4.Enabled=.t.
thisform.save1.command2.Enabled =.t.
thisform.save1.command3.Enabled =.t.
endif
this.Caption ='添加'
GO bottom
FOR i=1 to 3
mytext="text"+ALLTRIM(STR(i))
thisform.&mytext..enabled=.f.
endfor
thisform.Refresh
ENDIF