Results 1 to 16 of 16

Thread: [RESOLVED] Updating fields in a database

Threaded View

  1. #11
    Addicted Member
    Join Date
    Mar 2006
    Posts
    155

    Re: Updating fields in a database

    VB Code:
    1. Option Explicit
    2. Private cn As New ADODB.Connection
    3. Private rst As New ADODB.RecordSet
    4.  
    5. Private Sub cmdContinuar_Click()
    6.    
    7.     With rst
    8.         .AddNew
    9.         .Fields("data_inicio") = txtDInicial.Text
    10.         .Fields("data_fim") = txtDFinal.Text
    11.         .Update
    12.     End With
    13. End Sub
    14.  
    15.  
    16. Private Sub Form_Load()
    17.  
    18.     Dim Connectionstring As String
    19.    
    20.     Set cn = New ADODB.Connection
    21.     Set rst = New ADODB.RecordSet
    22.     rst.CursorLocation = adUseClient
    23.    
    24.     'Make Sure your Database Path is correct
    25.     Connstring = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\bd1.mdb;Persist Security Info=False"
    26.        
    27.    
    28.     cn.Open Connstring
    29.    
    30.     'Assuming Semana is a Database Table form bd1.mdb
    31.    
    32.     rst.Open "Semana", cn, adOpenStatic, adLockOptimistic, adCmdTable
    33.    
    34.     txtDInicial.Text = rst.Fields("data_inicio")
    35.     txtDFinal = rst.Fields("data_fim")
    36.    
    37. End Sub
    38.  
    39. Private Sub Form_Unload(Cancel As Integer)
    40.  
    41.    cn.Close
    42.    rst.Close
    43.    Set rst = Nothing
    44.    Set cn = Nothing
    45.  
    46. End Sub
    47.  
    48. Private Sub RSTMoveNxt_Click()
    49. rst.MoveNext
    50. If rst.EOF Then rst.MoveLast
    51. txtDInicial.Text = rst.Fields("data_inicio")
    52. txtDFinal.Text = rst.Fields("data_fim")
    53. End Sub
    54.  
    55. Private Sub RstMovePrev_Click()
    56. rst.MovePrevious
    57. If rst.BOF Then rst.MoveFirst
    58. txtDInicial.Text = rst.Fields("data_inicio")
    59. txtDFinal.Text = rst.Fields("data_fim")
    60.  
    61. End Sub

    This shuould Work.
    Last edited by RobDog888; Apr 4th, 2006 at 03:26 AM. Reason: Added [vbcode] tags

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