473,387 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Please go thru this code,,,,,UPDATE QUERY....

103 100+
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdEdit_Click()
  2. mName = Trim(ListView1.SelectedItem)
  3. mesge = MsgBox("Are you Sure you Want to Update " & mName & "?", vbOKCancel, "ERROR")
  4. '=MsgBox "You have selected the employee" & mName & "Continue", vbOKCancel, "PAYROLL"
  5. If mesge = vbOK Then
  6.     rs.Open "select * from empdetail where name = '" & mName & "'", conn, adOpenStatic, adLockOptimistic
  7.     Form1.txtid.Text = rs!id
  8.     Form1.txtname.Text = rs!Name
  9.     Form1.txtwhr.Text = rs!whours
  10.     Form1.txtrate.Text = rs!Rate
  11.     Form1.txtorate.Text = rs!otrate
  12.     txtid.Enabled = False
  13.     'txtname.SetFocus
  14.     Form1.txtname.SetFocus
  15.     rs.Close
  16. Set rs = Nothing
  17.  
  18.    Else
  19. conn.Execute "update empdetail set Name= '" & txtname & "',whours='" & txtwhrs & "',rate ='" & txtrate & "',otrate ='" & txtorate & "'"
  20. MsgBox "UPDATED NEW DETAILS", vbOKOnly, "UPDATED RECORDS"
  21.    End If
  22.  
the code above is to update the fields other than id in aparticular form,please go thru it,that is not working???
Jan 10 '08 #1
9 1394
QVeen72
1,445 Expert 1GB
Hi,

Not very clear as what you want to do here...
You ask a "Want to update", If user clicks OK, then You are displaying the records, or else, You are Running an Update Query..

What you are wanting to do here...?

REgards
Veena
Jan 10 '08 #2
Vbbeginner07
103 100+
Hi,
Not very clear as what you want to do here...
You ask a "Want to update", If user clicks OK, then You are displaying the records, or else, You are Running an Update Query..
What you are wanting to do here...?
REgards
Veena
i click one data from a listview then clicks ok,after that i can change all fields except id,which is a diasbled textbox,then after that i click update...then i need the message "updated"
Jan 10 '08 #3
debasisdas
8,127 Expert 4TB
You need to add the WHERE clause to the update query and pass the id to it.
Jan 10 '08 #4
QVeen72
1,445 Expert 1GB
Hi,

OK, in that case, Keep 2 seperate buttons: "Edit" and "Update"

Wtite this code in Edit_Click Event:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdEdit_Click()
  2.     mName = Trim(ListView1.SelectedItem)
  3.     rs.Open "select * from empdetail where name = '" & mName & "'", conn, adOpenStatic, adLockOptimistic
  4.     Form1.txtid.Text = rs!id
  5.     Form1.txtname.Text = rs!Name
  6.     Form1.txtwhr.Text = rs!whours
  7.     Form1.txtrate.Text = rs!Rate
  8.     Form1.txtorate.Text = rs!otrate
  9.     txtid.Enabled = False
  10.     Form1.txtname.SetFocus
  11.     rs.Close
  12.     Set rs = Nothing
  13. End Sub
  14.  
And Now Write This Code in Update_Click event:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdUpdate_Click()
  2.     mName = Trim(ListView1.SelectedItem)
  3.     mesge = MsgBox("Are you Sure you Want to Update " & mName & "?", vbOKCancel, "ERROR")
  4.     If mesge = vbOK Then
  5.         conn.Execute "update empdetail set Name= '" & txtname & "',whours='" &  txtwhrs & "',rate ='" & txtrate & "',otrate ='" & txtorate & "' Where ID = '" &     trim(txtID.Text) & "' "
  6.     MsgBox "UPDATED NEW DETAILS", vbOKOnly, "UPDATED RECORDS"
  7.     End If
  8. End Sub
  9.  
Both can be Clubed and done in Single Command button, depending on the Caption, but this will be easy to debug for beginner..


Regards
Veena
Jan 10 '08 #5
Vbbeginner07
103 100+
Hi,

Both can be Clubed and done in Single Command button, depending on the Caption, but this will be easy to debug for beginner..
Regards
Veena
veena,
that means we can combine both codes as i have done in #1,if so ny bugs occurs or should have to add enough codings to for that being under a single command button,nythng wrong please explain........regarding that...Nyway Thanks in advance for ur reply
Jan 10 '08 #6
QVeen72
1,445 Expert 1GB
Hi,

Yes, you can Club Both Functions in One Command button . In Form Load or design time make the caption of cmdEdit = "Edit"
and change your code this way :

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdEdit_Click()
  2. mName = Trim(ListView1.SelectedItem)
  3. If cmdEdit.Caption = "Edit" Then
  4.     rs.Open "select * from empdetail where name = '" & mName & "'", conn, adOpenStatic, adLockOptimistic
  5.     Form1.txtid.Text = rs!id
  6.     Form1.txtname.Text = rs!Name
  7.     Form1.txtwhr.Text = rs!whours
  8.     Form1.txtrate.Text = rs!Rate
  9.     Form1.txtorate.Text = rs!otrate
  10.     txtid.Enabled = False
  11.     Form1.txtname.SetFocus
  12.     rs.Close
  13.     Set rs = Nothing
  14.     cmdEdit.Caption = "Update"
  15. Else
  16.     mesge = MsgBox("Are you Sure you Want to Update " & mName & "?", vbOKCancel, "ERROR")
  17.     If mesge = vbOK Then
  18.         conn.Execute "update empdetail set Name= '" & txtname & "',whours='" &     txtwhrs & "',rate ='" & txtrate & "',otrate ='" & txtorate & "' Where ID = '" & txtID.Text & "'"
  19.         MsgBox "UPDATED NEW DETAILS", vbOKOnly, "UPDATED RECORDS"
  20.    End If
  21.    cmdEdit.Caption = "Edit"
  22.     Form1.txtid.Text = ""
  23.     Form1.txtname.Text =""
  24.     Form1.txtwhr.Text = ""
  25.     Form1.txtrate.Text = ""
  26.     Form1.txtorate.Text = ""
  27. End If
  28.  
Regards
Veena
Jan 10 '08 #7
Vbbeginner07
103 100+
Hi,

Yes, you can Club Both Functions in One Command button . In Form Load or design time make the caption of cmdEdit = "Edit"
and change your code this way :

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdEdit_Click()
  2. mName = Trim(ListView1.SelectedItem)
  3. If cmdEdit.Caption = "Edit" Then    rs.Open "select * from empdetail where name = '" & mName & "'", conn, adOpenStatic, adLockOptimistic
  4.     Form1.txtid.Text = rs!id
  5.     Form1.txtname.Text = rs!Name
  6.     Form1.txtwhr.Text = rs!whours
  7.     Form1.txtrate.Text = rs!Rate
  8.     Form1.txtorate.Text = rs!otrate
  9.     txtid.Enabled = False
  10.     Form1.txtname.SetFocus
  11.     rs.Close
  12.     Set rs = Nothing
  13.     cmdEdit.Caption = "Update"
  14. Else
  15.     mesge = MsgBox("Are you Sure you Want to Update " & mName & "?", vbOKCancel, "ERROR")
  16.     If mesge = vbOK Then
  17.         conn.Execute "update empdetail set Name= '" & txtname & "',whours='" &     txtwhrs & "',rate ='" & txtrate & "',otrate ='" & txtorate & "' Where ID = '" & txtID.Text & "'"        MsgBox "UPDATED NEW DETAILS", vbOKOnly, "UPDATED RECORDS"
  18.    End If
  19.    cmdEdit.Caption = "Edit"
  20.     Form1.txtid.Text = ""
  21.     Form1.txtname.Text =""
  22.     Form1.txtwhr.Text = ""
  23.     Form1.txtrate.Text = ""
  24.     Form1.txtorate.Text = ""
  25. End If
  26.  
Regards
Veena
the control moves from,the first cmdedit.caption =edit to the update statement
where i have kept the caption in design time to edit,error showing cannot convert varchar to numeric,
Jan 10 '08 #8
QVeen72
1,445 Expert 1GB
Hi,

Well, You must be having ID as numeric field, change the update statement to :

Expand|Select|Wrap|Line Numbers
  1. conn.Execute "update empdetail set Name= '" & txtname & "',whours='" &     txtwhrs & "',rate ='" & txtrate & "',otrate ='" & txtorate & "' Where ID = " _
  2. &  Val(txtID.Text)
  3. MsgBox "UPDATED NEW DETAILS", vbOKOnly, "UPDATED RECORDS
  4.  
Regards
Veena
Jan 10 '08 #9
Vbbeginner07
103 100+
Hi,

Well, You must be having ID as numeric field, change the update statement to :

Expand|Select|Wrap|Line Numbers
  1. conn.Execute "update empdetail set Name= '" & txtname & "',whours='" &     txtwhrs & "',rate ='" & txtrate & "',otrate ='" & txtorate & "' Where ID = " _
  2. &  Val(txtID.Text)
  3. MsgBox "UPDATED NEW DETAILS", vbOKOnly, "UPDATED RECORDS
  4.  
Regards
Veena
Thanx VEENA ,now its working!!!
Jan 10 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Bruce W...1 | last post by:
I do a query to MySQL using PHP. Well actually I do too many of them which is the problem, it's too slow. I think maybe an inner join or something would be better but I can't figure this out. ...
4
by: Orion | last post by:
Hi, This is kind of last minute, I have a day and a half left to figure this out. I'm working on a project using ms-sqlserver. We are creating a ticket sales system, as part of the system, I...
8
by: Tcs | last post by:
I've been stumped on this for quite a while. I don't know if it's so simple that I just can't see it, or it's really possible. (Obviously, I HOPE it IS possible.) I'm trying to get my queries...
2
by: vulcaned | last post by:
I'm thinking I might want to move the back-end to one of my Access97 applications to SQLServer instead of continuing to use Access jet but before I start/do that I have several questions I'm hoping...
11
by: DFS | last post by:
Architecture: Access 2003 client, Oracle 9i repository, no Access security in place, ODBC linked tables. 100 or so users, in 3 or 4 groups (Oracle roles actually): Admins, Updaters and ReadOnly....
3
by: Shapper | last post by:
Hello, I have created 3 functions to insert, update and delete an Access database record. The Insert and the Delete code are working fine. The update is not. I checked and my database has all...
5
by: kanley | last post by:
I have a main table with a text description field. In this field, its populated with a string of data. I need to identify from this string of data the name of the vendor using some keywords. I...
4
by: Dave | last post by:
I have a global.asax file with Application_Start defined and create some static data there and in another module used in the asp.net application and I realize that static data is shared amongst...
1
by: Sergey Topychkanov | last post by:
I have SQL SERVER 2008 Express and C# Express 2008 - both sp1. I can remove and update data in my database only thru direct SQL query thru database explorer, but quite unable to do it through...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.