1,105,534 Community Members

vb6 Edit database record

Member Avatar
Shodow
Junior Poster
178 posts since Jan 2011
Reputation Points: 4 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

how to edit a record in database by using vb6, i don't any clue :(

Member Avatar
AndreRet
Industrious Poster
4,492 posts since Jan 2008
Reputation Points: 362 [?]
Q&As Helped to Solve: 499 [?]
Skill Endorsements: 24 [?]
 
0
 

What database are you using, msaccess, sql, mysql?
What connection are you using, data control or ADO?

Member Avatar
Shodow
Junior Poster
178 posts since Jan 2011
Reputation Points: 4 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

ms access
ado po

Member Avatar
AndreRet
Industrious Poster
4,492 posts since Jan 2008
Reputation Points: 362 [?]
Q&As Helped to Solve: 499 [?]
Skill Endorsements: 24 [?]
 
0
 
Dim conn as ADODB.Connection
Dim Rs As ADODB.Recordset

Set conn = new ADODB.Connection
Set Rs = New ADODB.Recordset

'Do your connection to access code here

Rs.Open "SELECT * FROM MyTable", conn, adOpenStatic, adLockOptimistic

Rs!Fieldname1 = Text1.Text
Rs.Update

And that is it...:)

Member Avatar
Shodow
Junior Poster
178 posts since Jan 2011
Reputation Points: 4 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

'Do your connection to access code here

connection? example po

Member Avatar
AndreRet
Industrious Poster
4,492 posts since Jan 2008
Reputation Points: 362 [?]
Q&As Helped to Solve: 499 [?]
Skill Endorsements: 24 [?]
 
0
 
Conn.Open = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\YourDatabaseName.MDB;Persist Security Info=False"
Member Avatar
Shodow
Junior Poster
178 posts since Jan 2011
Reputation Points: 4 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

will this edit the highlighted record?

Member Avatar
Shodow
Junior Poster
178 posts since Jan 2011
Reputation Points: 4 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 
Private Sub Toolbar_ButtonClick(ByVal Button As MSComctlLib.Button)
Attachments wew.JPG 39.85KB
Member Avatar
AndreRet
Industrious Poster
4,492 posts since Jan 2008
Reputation Points: 362 [?]
Q&As Helped to Solve: 499 [?]
Skill Endorsements: 24 [?]
 
0
 

What do you mean with "highlighted record"? Where is it highlighted?

The code above will edit an existing record that you have chosen.

Member Avatar
AndreRet
Industrious Poster
4,492 posts since Jan 2008
Reputation Points: 362 [?]
Q&As Helped to Solve: 499 [?]
Skill Endorsements: 24 [?]
 
0
 

I also do not understand your picture, what is it suppose to show?

Member Avatar
Shodow
Junior Poster
178 posts since Jan 2011
Reputation Points: 4 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

error about this

Private Sub Toolbar_ButtonClick(ByVal Button As MSComctlLib.Button)
Member Avatar
AndreRet
Industrious Poster
4,492 posts since Jan 2008
Reputation Points: 362 [?]
Q&As Helped to Solve: 499 [?]
Skill Endorsements: 24 [?]
 
0
 

What is the code under this (below)?

Member Avatar
Shodow
Junior Poster
178 posts since Jan 2011
Reputation Points: 4 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 
Private Sub Toolbar_ButtonClick(ByVal Button As MSComctlLib.Button)
If Button.Index = 1 Then
frmList.Show
End If
If Button.Index = 2 Then
frmReserve.Show
End If
If Button.Index = 3 Then
    frmList.Adodc.Refresh
    frmList.DataGrid.Refresh
End If
If Button.Index = 4 Then

Dim conn As ADODB.Connection
Dim Rs As ADODB.Recordset

Set conn = New ADODB.Connection
Set Rs = New ADODB.Recordset

conn.Open = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Database1.mdb;Persist Security Info=False"

Rs.Open "SELECT * FROM List", conn, adOpenStatic, adLockOptimistic

Rs!CustomerName = txtName.Text
Rs!ContactNumber = txtContact.Text
Rs.Update
End If
End Sub
Member Avatar
abelingaw
Posting Whiz in Training
247 posts since Jun 2008
Reputation Points: 69 [?]
Q&As Helped to Solve: 32 [?]
Skill Endorsements: 2 [?]
 
0
 

Don't put the the code in the toolbar.

Place it in your command button (cmdUpdate) in your Modify form.

Member Avatar
AndreRet
Industrious Poster
4,492 posts since Jan 2008
Reputation Points: 362 [?]
Q&As Helped to Solve: 499 [?]
Skill Endorsements: 24 [?]
 
0
 

Your code is porfect. Reference the ms active x data objects.:)

Member Avatar
Shodow
Junior Poster
178 posts since Jan 2011
Reputation Points: 4 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

my modify command button is on the toolbar

Member Avatar
Shodow
Junior Poster
178 posts since Jan 2011
Reputation Points: 4 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

when i click modify

Attachments 1.JPG 59.12KB 2.JPG 109.62KB
Member Avatar
AndreRet
Industrious Poster
4,492 posts since Jan 2008
Reputation Points: 362 [?]
Q&As Helped to Solve: 499 [?]
Skill Endorsements: 24 [?]
 
0
 

Do you have a control named txtName on your form?

Member Avatar
Shodow
Junior Poster
178 posts since Jan 2011
Reputation Points: 4 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

yes

Member Avatar
AndreRet
Industrious Poster
4,492 posts since Jan 2008
Reputation Points: 362 [?]
Q&As Helped to Solve: 499 [?]
Skill Endorsements: 24 [?]
 
0
 

Then your problem lies with the field name CustomerName. Is that spelled correctly. It is not the recordset, that was declared etc. Is your open call correct, in other words the table name List exists?

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: