954,559 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Editing a record!

help theres nothing happen everytime i search a record

heres my code

Dim a
a = InputBox("Input Product Code :", "Find", "")
If a = "" Then
Exit Sub
End If
Set rs = New ADODB.Recordset
rs.Open "Select * from Product where pcode='" & a & "'", cn, adOpenStatic, adLockPessimistic
Set MSHFlexGrid1.DataSource = rs
If rs.RecordCount > 0 Then
rs.Fields("pcode") = Text1.Text
rs.Fields("brandname") = Text2.Text
rs.Fields("genericname") = Text3.Text
rs.Fields("price") = Text4.Text
Command1.Enabled = False
Command2.Enabled = False
Command4.Enabled = False
Command5.Enabled = False
End If

nothing happen to my text fields

ryan311
Posting Whiz in Training
254 posts since Jul 2008
Reputation Points: 3
Solved Threads: 5
 
Dim a , strsql as string 

'pls check your inputbox forget using it
'idont have any vb6 installed in my pc , now using csharp2005
a = InputBox("Input Product Code :", "Find", "")
If a = "" Then Exit Sub

'think this would help 

strsql = " select * from Product " 
strsql = strsql & " where " 
strsql = strsql & " pcode='" & trim(a) & "'"

Set rs = New ADODB.Recordset
rs.CursorLocation = AdUseClient

rs.open strsql, cn, AdOpenForwardonly, AdLockReadonly
'exit if no record 
if rs.Recordcount = 0 then exit sub
if rs.Recordcount > 0 Then 
          'display record in textbox
          'hope it helps 
          Text1.text = rs.Fields("pcode") 
          Text2.Text= rs.Fields("brandname") 
          etc....
          
         Set MSHFlexGrid1.DataSource = rs
end if
Command1.Enabled = False
Command2.Enabled = False
Command4.Enabled = False
Command5.Enabled = False
Joel Salvo
Newbie Poster
3 posts since Mar 2008
Reputation Points: 10
Solved Threads: 1
 

thanks its work but i have problem in saving a data

Set rs = New ADODB.Recordset
rs.Open "Select * from Product", cn, adOpenKeyset, adLockPessimistic
If Not rs.EOF Then
rs.Fields("pcode").Value = Text1.Text
rs.Fields("brandname").Value = Text2.Text
rs.Fields("genericname").Value = Text3.Text
rs.Fields("price").Value = Text4.Text
rs.Update
End If

i hope you can help me :(

ryan311
Posting Whiz in Training
254 posts since Jul 2008
Reputation Points: 3
Solved Threads: 5
 

bump

ryan311
Posting Whiz in Training
254 posts since Jul 2008
Reputation Points: 3
Solved Threads: 5
 

I'm a little confused.... you are trying to save data? If so, you wouldn't open a connection to the database with a Select... Select is used to retrieve rows and columns from the database table.... I think you want something like with like
UPDATE table SET field = 'whatever' WHERE column = 'something'

Comatose
Taboo Programmer
Team Colleague
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
 

yes i want to update what he edited from my database record. .

ryan311
Posting Whiz in Training
254 posts since Jul 2008
Reputation Points: 3
Solved Threads: 5
 

Right... So a select statement isn't meant for updating/editing... it's only meant for retrieval. You need the update sql query.

Comatose
Taboo Programmer
Team Colleague
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
 

ok i try :)

ryan311
Posting Whiz in Training
254 posts since Jul 2008
Reputation Points: 3
Solved Threads: 5
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You