建议按键改成:新增,刪除,保存,取消修改,首筆,上一筆,下一筆,末筆 以下代码未经测试和优化。请楼主自行完善。dim isUpdate as boolean private sub txtel_no_validate(Cancel As Boolean) '其他的文本框也同样作此判断。 isupdate=true end sub private sub button1_click(index as integer) dim lastkey as integerSelect Case Index Case 0 txtel_no.Text = "" txtel_name1.Text = "" txtel_size = "" txtel_prno = "" txtel_unit = "" lastkey=0 Case 1 if rs1.eof=false and rs1.bof=false then rs1.delete if rs1.eof=false and rs1.bof=false then txtel_no.Text = rs1.Fields("el_no").Value txtel_name1.Text = rs1!el_name1.Value txtel_size = rs1.Fields("el_size").Value txtel_prno = rs1!el_prno.Value txtel_unit = rs1.Fields("el_unit").Value else txtel_no.Text = "" txtel_name1.Text = "" txtel_size = "" txtel_prno = "" txtel_unit = "" end if lastkey=1 Case 2 if lastkey=0 then rs1.addnew if rs1.eof=false and rs1.bof=false then rs1.Fields("el_no").Value=txtel_no.Text rs1!el_name1.Value=txtel_name1.Text rs1.Fields("el_size").Value=txtel_size rs1!el_prno.Value=txtel_prno rs1.Fields("el_unit").Value=txtel_unit rs1.update end if lastkey=2 Case 3 if rs1.bof=false and rs1.eof=false then txtel_no.Text = rs1.Fields("el_no").Value txtel_name1.Text = rs1!el_name1.Value txtel_size = rs1.Fields("el_size").Value txtel_prno = rs1!el_prno.Value txtel_unit = rs1.Fields("el_unit").Value end if lastkey=3 Case 4 if isupdate then if msgbox ("新增的内容尚未保存,要保存吗",vbyesno)=vbyes then if lastkey=0 then rs1.addnew ... '这里同“保存”按键 end if end if rs.MoveFirst txtel_no.Text = rs1.Fields("el_no").Value txtel_name1.Text = rs1!el_name1.Value txtel_size = rs1.Fields("el_size").Value txtel_prno = rs1!el_prno.Value txtel_unit = rs1.Fields("el_unit").Value lastkey=4 Case 5 if isupdate then if msgbox ("新增的内容尚未保存,要保存吗",vbyesno)=vbyes then if lastkey=0 then rs1.addnew ... '这里同“保存”按键 end if end if if rs1.bof=false and rs1.eof=false then rs.Moveprevious if rs1.bof=true then rs1.movefirst end if txtel_no.Text = rs1.Fields("el_no").Value txtel_name1.Text = rs1!el_name1.Value txtel_size = rs1.Fields("el_size").Value txtel_prno = rs1!el_prno.Value txtel_unit = rs1.Fields("el_unit").Value lastkey=5 Case 6 '类似“上一笔”的处理。 Case 7 '类似“第一笔”的处理。 Case 8 Unload Me End Select) end sub
Case 2部分的代码加一点: if lastkey=0 then rs1.addnew if rs1.eof=false and rs1.bof=false then rs1.Fields("el_no").Value=txtel_no.Text rs1!el_name1.Value=txtel_name1.Text rs1.Fields("el_size").Value=txtel_size rs1!el_prno.Value=txtel_prno rs1.Fields("el_unit").Value=txtel_unit rs1.update isupdate=false '加这一句。case 4至case 7中相关的代码中也要加上这句。 end if lastkey=2
以下代码未经测试和优化。请楼主自行完善。dim isUpdate as boolean private sub txtel_no_validate(Cancel As Boolean) '其他的文本框也同样作此判断。
isupdate=true
end sub
private sub button1_click(index as integer)
dim lastkey as integerSelect Case Index
Case 0
txtel_no.Text = ""
txtel_name1.Text = ""
txtel_size = ""
txtel_prno = ""
txtel_unit = ""
lastkey=0
Case 1
if rs1.eof=false and rs1.bof=false then rs1.delete
if rs1.eof=false and rs1.bof=false then
txtel_no.Text = rs1.Fields("el_no").Value
txtel_name1.Text = rs1!el_name1.Value
txtel_size = rs1.Fields("el_size").Value
txtel_prno = rs1!el_prno.Value
txtel_unit = rs1.Fields("el_unit").Value
else
txtel_no.Text = ""
txtel_name1.Text = ""
txtel_size = ""
txtel_prno = ""
txtel_unit = ""
end if
lastkey=1
Case 2
if lastkey=0 then rs1.addnew
if rs1.eof=false and rs1.bof=false then
rs1.Fields("el_no").Value=txtel_no.Text
rs1!el_name1.Value=txtel_name1.Text
rs1.Fields("el_size").Value=txtel_size
rs1!el_prno.Value=txtel_prno
rs1.Fields("el_unit").Value=txtel_unit rs1.update
end if
lastkey=2
Case 3
if rs1.bof=false and rs1.eof=false then
txtel_no.Text = rs1.Fields("el_no").Value
txtel_name1.Text = rs1!el_name1.Value
txtel_size = rs1.Fields("el_size").Value
txtel_prno = rs1!el_prno.Value
txtel_unit = rs1.Fields("el_unit").Value
end if
lastkey=3
Case 4
if isupdate then
if msgbox ("新增的内容尚未保存,要保存吗",vbyesno)=vbyes then
if lastkey=0 then rs1.addnew
... '这里同“保存”按键
end if
end if
rs.MoveFirst
txtel_no.Text = rs1.Fields("el_no").Value
txtel_name1.Text = rs1!el_name1.Value
txtel_size = rs1.Fields("el_size").Value
txtel_prno = rs1!el_prno.Value
txtel_unit = rs1.Fields("el_unit").Value
lastkey=4
Case 5
if isupdate then
if msgbox ("新增的内容尚未保存,要保存吗",vbyesno)=vbyes then
if lastkey=0 then rs1.addnew
... '这里同“保存”按键
end if
end if
if rs1.bof=false and rs1.eof=false then
rs.Moveprevious
if rs1.bof=true then rs1.movefirst
end if
txtel_no.Text = rs1.Fields("el_no").Value
txtel_name1.Text = rs1!el_name1.Value
txtel_size = rs1.Fields("el_size").Value
txtel_prno = rs1!el_prno.Value
txtel_unit = rs1.Fields("el_unit").Value
lastkey=5
Case 6
'类似“上一笔”的处理。
Case 7
'类似“第一笔”的处理。
Case 8
Unload Me
End Select)
end sub
if lastkey=0 then rs1.addnew
if rs1.eof=false and rs1.bof=false then
rs1.Fields("el_no").Value=txtel_no.Text
rs1!el_name1.Value=txtel_name1.Text
rs1.Fields("el_size").Value=txtel_size
rs1!el_prno.Value=txtel_prno
rs1.Fields("el_unit").Value=txtel_unit rs1.update
isupdate=false '加这一句。case 4至case 7中相关的代码中也要加上这句。
end if
lastkey=2