Results 1 to 16 of 16

Thread: [RESOLVED] Updating fields in a database

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Posts
    74

    Resolved [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:
    1. Private Sub cmd1_Click()
    2.    Dim db As DAO.Database
    3.    Dim rst As DAO.Recordset
    4.  
    5.    Set db = CurrentDb
    6.    Set rst = db.OpenRecordset("Table1")
    7.  
    8.    rst.AddNew
    9.    rst("test").Value = txt1
    10.    rst.Update
    11. End Sub

    VB Code:
    1. Private Sub cmd1_Click()
    2.  
    3.  
    4.     Dim rst As ADODB.Recordset
    5.  
    6.     Set rst = New ADODB.Recordset
    7.    
    8.  
    9.     rst.Open "Table1", CurrentProject.Connection, adOpenStatic, adLockOptimistic
    10.    
    11.     If rst.Supports(adAddNew) Then
    12.         rst.AddNew
    13.         rst.Fields("test") = "txt1"
    14.         rst.Update
    15.     End If
    16.    
    17.  
    18.     rst.Close
    19.     Set rst = Nothing
    20.    
    21. 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
  •  



Click Here to Expand Forum to Full Width