VBA Access 2003更新问题 [英] vba access 2003 update problem
问题描述
确定"按钮的代码:笑:
code for ok button :laugh:
Dim strconn As String
Dim myconn As New ADODB.Connection
Dim myrecordset As New ADODB.recordset
strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Documents and Settings\vijay\My Documents\my application\db2.mdb;Persist Security Info=True"
Set myconn = New ADODB.Connection
myconn.Open (strconn)
Set myrecordset = New ADODB.recordset
Set myrecordset = myconn.Execute("SELECT * FROM Table1 WHERE cid='" & txtsearch.Value & "'")
If myrecordset.EOF = False Then
txtcid = myrecordset.Fields("cid")
txtnat = myrecordset.Fields("nat")
txtname = myrecordset.Fields("e_name")
txtsalary = myrecordset.Fields("salary")
txtl1 = myrecordset.Fields("dol1")
txtl2 = myrecordset.Fields("dol2")
txtl3 = myrecordset.Fields("dol3")
txtl4 = myrecordset.Fields("dol4")
txtl5 = myrecordset.Fields("dol5")
txtl6 = myrecordset.Fields("dol6")
txtl7 = myrecordset.Fields("dol7")
txtl8 = myrecordset.Fields("dol8")
txtl9 = myrecordset.Fields("dol9")
txt10 = myrecordset.Fields("dol10")
txt11 = myrecordset.Fields("dol11")
txt12 = myrecordset.Fields("dol12")
txt13 = myrecordset.Fields("dol13")
txt14 = myrecordset.Fields("dol14")
txt15 = myrecordset.Fields("dol15")
txt16 = myrecordset.Fields("dol16")
txt17 = myrecordset.Fields("dol17")
txt18 = myrecordset.Fields("dol18")
txt19 = myrecordset.Fields("dol19")
txt20 = myrecordset.Fields("dol20")
MsgBox ("ok")
Else
MsgBox ("no record")
End If
更新按钮的代码:mad:
code for update button :mad:
If IsNull(txtl1) = True Then
MsgBox ("please choose date first")
ElseIf IsNull(txtl1) = False Then
a = CStr(txtl1)
myconn.Execute ("update table1 set dol1='" & a & "' where cid='" & txtsearch.Value & "'")
MsgBox ("your data has been saved")
ElseIf IsNull(txtl2) = True Then
MsgBox ("please choose date first")
ElseIf IsNull(txtl2) = False Then
b = CStr(txtl2)
myconn.Execute ("update table1 set dol2='" & b & "' where cid='" & txtsearch.Value & "' ")
MsgBox ("your data has been saved")
End If
实际问题:疯狂:
我正在使用ms访问表单2003和访问数据库2003
ok按钮搜索结果并将其显示在文本框中,效果很好
但问题在于更新按钮
确定时,已经有用于文本框的数据,但是在第五个及以后的文本框中没有数据,但是这次他输入了日期值,并且只更新了该值.下次第六个文本框将具有日期,并且此值应更新.
下次以同样的方式而不影响旧值
我正在使用确定"按钮和更新"按钮的单一表单
所有字段只有一张表格.除了平民,国籍,姓名和薪水均为日期类型字段.这是一个与请假相关的项目,一个人一次可以请假一个日期,因此我需要一次更新一个日期字段.
当同一个人来请假时,我将根据民事身份进行搜索,将显示其身份证号码,姓名,国籍,薪水和以前的请假,然后我将输入下一个请假日期并再次更新.等等
请帮助我
在此先感谢
real problem:mad:
i am using ms access forms 2003 and access database 2003
ok button search the result and display it in textboxes and it is working well
but problem is with update button
when ok finish there is data in for textboxes already but there is no data in fifth and onward textboxes but this time he enter the date value and do update only this value should be updated. next time sixth textbox will have date and this value should be updated.
next time in same manner without affecting old values
i am using single form for ok button and update button
there is only one table for all fields.except civilid,nationality, name and salary all are of date type field. it is a leave related project a person can get leave for one date at a time and so i need to update one date field at a time .
when same person come for leave i will search according to civilid it will display his cid,name,nationality,salary and previous leave and then i will enter next leave date and update again. and so on
please help me
thanks in advance
推荐答案
您在OK_Click()
过程中将Dim myconn As New ADODB.Connection
用作局部变量,所以...
您应该在Update_Click()
过程中声明相同的对象(变量).阅读有关"变量范围"的更多信息.
要更新记录,您应该使用Command
object.
You usedDim myconn As New ADODB.Connection
as local variable inOK_Click()
procedure, so...
You should declare the same object (variable) inUpdate_Click()
procedure. Read more about "scope of variables".
To update records you should useCommand
object.
这篇关于VBA Access 2003更新问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!