Results 1 to 13 of 13

Thread: sending listbox contents to access

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    basically this is the code i was using before Kenneth's suggestion

    Private Sub cmdOK_Click()
    
    
    If cbohandler.Value = "" Or txtClaim.Value = "" Or txtrecs.Value = "" Or cboCHO.Value = "" Or lstissue.Value = "" Or txtcommentry.Value = "" Then
        
        MsgBox "Please enter all fields before continuing!", vbCritical
        
        Exit Sub
        Else
      
    If txtcommentry.Value = "" Then txtcommentry.Value = "N/A"
    If txtrecs.Value = "" Then txtreason.Value = "N/A"
    ' exports data from the active form to a table in an Access database
    Dim cn As ADODB.Connection
    Dim rs As ADODB.Recordset
    
    
        ' connect to the Access database
        Set cn = New ADODB.Connection
        cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & "Data Source=cho.mdb;"
    
    
        ' open a recordset
    Set rs = New ADODB.Recordset
        rs.Open "SELECT * FROM [chotable]", cn, adOpenDynamic, adLockOptimistic
    
    
    With rs
    
    
    .AddNew
        .Fields("Handler Name") = cbohandler.Value
        .Fields("Claim Number") = txtClaim.Value
        .Fields("CHO") = cboCHO.Value
        .Fields("Issue(s)") = lstissue.Value
        .Fields("Commentry") = txtcommentry.Value
        .Fields("Recommendations") = txtrecs.Value
        
                .Update ' stores the new record
            End With
        rs.Close
        Set rs = Nothing
        cn.Close
        Set cn = Nothing
        End If
     Unload Me
     MsgBox "Entry Added Successfully", vbOKOnly
    End Sub
    Last edited by CuriousGeorg; 10-25-2013 at 12:31 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
  •