Results 1 to 6 of 6

Thread: DELETE PROBLEM - Cannot DELETE after ADDing new record or UPDATING ?

Threaded View

  1. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2004
    Posts
    101
    I've decided to post my code... please make any suggestions you see fit, but please not major overhauls as I've spent too much time on this already and need to be moving on (although in saying that Adding/Updating/Deleting are essentials!)

    I have dropping the opening and closing of the recordset as it was making no difference and resorted to my original code, which is displayed below.


    Here is my code for the Add button:
    Code:
    Private Sub cmdAdd_Click()
    
    txtStatus.Text = "Adding New Record..."
    
    
    'db is globally dimmed
    
    Set db = New Connection
    db.CursorLocation = adUseServer
    db.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & ConnPath & "\DatabaseDB.mdb;" 
    
    
    Dim InsertNewTask As String
    
    InsertNewTask= "INSERT INTO Task(TaskID) VALUES('" & txtTaskID & "')"
    
    db.Execute InsertNewTask
    
    
    End Sub


    And here is my code for the Update button:
    Code:
    Private cmdUpdate_Click()
    
    
    Dim db As Connection
    Set db = New Connection
    db.CursorLocation = adUseClient
    db.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & ConnPath & "\DatabaseDB.mdb;"
    
    Dim UpdateTaskRecord As String
    
    UpdateTaskRecord = "UPDATE Task SET TaskDescription='" & txtTaskDescription & "', TaskDate='" & txtTaskDate & "', TaskTime='" & txtTaskTime & "', CustomerID='" & txtCustomerID & "' WHERE TASK.TaskID='" & txtTaskID & "'"
    
    
    db.Execute UpdateTaskRecord 
    
    
    txtStatus.Text = "Save Successful"
    
    
      If CStr(adoPrimaryRS.AbsolutePosition) = (-1) Then
      txtCount.Text = "Total: 0"
      Else: txtCount.Text = "Total: " & CStr(adoPrimaryRS.RecordCount)
      End If
    
    
      mbEditFlag = False
      mbAddNewFlag = False
      mbDataChanged = False
    
    Exit Sub
    
    
    If Not IsEmpty(adoPrimaryRS) Then
    cmdDelete.Enabled = True
    Else
    cmdDelete.Enabled = False
    End If
    
    End Sub

    Please make any suggestions you think of. Thanks
    Last edited by VBKid04; Apr 12th, 2004 at 11:01 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