|
-
Mar 29th, 2006, 02:03 PM
#1
Thread Starter
Lively Member
[RESOLVED] Updating fields in a database
First, before i say anything really absurd, i'm just starting with visual basic, so i don't know that much about it.
Ok so here is the deal, i'm creating a database in MS Access 2002, and i have several independent fields, that once you click a button are updated into a table. Something like i write "bob" in a text box, and when i press a button "bob" is added to my table.
Now i managed to get this to work, but after developing a bit more the datbase it stoped working for some reason. Then i tested in a new batabase, with just a table with 2 fields, and a simple form, and it didn't worked either, so i guess there's something wrong with the code i'm using.
I saw 2 different tutorials on how to do this, neither of them work, so i'll post both here:
VB Code:
Private Sub cmd1_Click()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset("Table1")
rst.AddNew
rst("test").Value = txt1
rst.Update
End Sub
VB Code:
Private Sub cmd1_Click()
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
rst.Open "Table1", CurrentProject.Connection, adOpenStatic, adLockOptimistic
If rst.Supports(adAddNew) Then
rst.AddNew
rst.Fields("test") = "txt1"
rst.Update
End If
rst.Close
Set rst = Nothing
End Sub
So any ideas why it doesn't work (despite it being working before)?
Last edited by BeKay; Apr 7th, 2006 at 11:48 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|