Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Via VB delete row from SubForm -- Weird stuff??

Status
Not open for further replies.

xenofoob

Programmer
Oct 4, 2004
28
NL
heya

I have a subform with the products from my table. Next to each row there is a little button. Onclick that button results that the following code will be executed:
Code:
Private Sub Knop14_Click()
On Error GoTo Err_Knop14_Click

    Dim strSQL As String
    Dim l_cmdTmp As New ADODB.Command
    Dim l_rsTmp As ADODB.Recordset

    l_sConnect = "PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
                "Data Source=C:\Documents and Settings\gebruiker\Desktop\Bier_final_2.3.mdb;" & _
                "User ID=admin;" & _
                ";Password="
    
    'Set connection
    Set m_cnConnection = New ADODB.Connection
    With m_cnConnection
        .ConnectionString = l_sConnect
        .Open
        .CursorLocation = adUseClient
    End With
    
    Set rs = New ADODB.Recordset
    rs.ActiveConnection = CurrentProject.Connection
     
    strSQL = "DELETE " & _
             "FROM bestelproduct " & _
             "WHERE ([Product_nr]= '" & Me.Product_nr.value & "' AND [Bestel_nr]= " & Me.Bestel_nr.value & " )"

    'Run SQL
    With l_cmdTmp
        .ActiveConnection = m_cnConnection
        .CommandText = strSQL
        .CommandType = adCmdText
        .CommandTimeout = 0
        Set l_rsTmp = .Execute
    End With
    
    'Set recordset to modular variable
    Set m_rsRecordset = l_rsTmp
    
    Form_BestellingSubformulier.Requery
    Form_BestellingSubformulier.Refresh

Exit_Knop14_Click:
    Exit Sub

Err_Knop14_Click:
    MsgBox Err.Description
    Resume Exit_Knop14_Click
    
End Sub

After clicking the button (and running code) the row is deleted. The weird thing is that my form is not updated directly. First I see #deleted# at the unique column and when I focus on another field the row is going to be deleted....

Does anyone knows an answer.
 
Already find an answer at my question:

Maybe someone can use it :)

Instead of executing own query use Access's standard code (I would not wanted to get te warnings):
Code:
    'Disable warnings :D
    DoCmd.SetWarnings False
    
    'Default access delete row
    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top