Click here to Skip to main content
15,914,419 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
code for ok button :laugh:
VB
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

code for update button :mad:
VB
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

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
Posted
Updated 27-Nov-10 21:34pm
v2

1 solution

You used Dim myconn As New ADODB.Connection as local variable in OK_Click() procedure, so...
You should declare the same object (variable) in Update_Click() procedure. Read more about "scope of variables".

To update records you should use Command object.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900