Results 1 to 4 of 4

Thread: How to delete current record in bounded form?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Unhappy How to delete current record in bounded form?

    Hi guys. I made bounded maintenance form customer table in my access db.
    But when I try to delete a record by clicking on the delete button I get
    the following error. I be happy if some one help me delete record successfully. Thanks


    Code:
    Run-time error '91'
    
    Object variable or with block variable not set
    http://i5.photobucket.com/albums/y18...eleteerror.jpg
    pic ===>delete error


    Code:
    Option Compare Database
    
    
    
    Private Sub cmdSearch_Click()
        Dim strStudentRef As String
        Dim strSearch As String
        
    'Check txtSearch for Null value or Nill Entry first.
    
        If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
            MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
            Me![txtSearch].SetFocus
        Exit Sub
    End If
    '---------------------------------------------------------------
            
    'Performs the search using value entered into txtSearch
    'and evaluates this against values in customerno
            
        DoCmd.ShowAllRecords
        DoCmd.GoToControl ("customerno")
        DoCmd.FindRecord Me!txtSearch
            
        customerno.SetFocus
        strStudentRef = customerno.Text
        txtSearch.SetFocus
        strSearch = txtSearch.Text
            
    'If matching record found sets focus in customerno and shows msgbox
    'and clears search control
    
        If strStudentRef = strSearch Then
            MsgBox "Match Found For: " & strSearch, , "Congratulations!"
            customerno.SetFocus
            txtSearch = ""
            
        'If value not found sets focus back to txtSearch and shows msgbox
            Else
                MsgBox "Match Not Found For: " & strSearch & " - Please Try Again.", _
                , "Invalid Search Criterion!"
                txtSearch.SetFocus
        End If
    End Sub
    
    
    
    
    
    
    
    Private Sub Command14_Click()
    '''On Error GoTo Err_CmdAdd_Click
        '''Me.DataEntry = True
        '''Me.CmdFilter.Visible = False
        '''Me.CmdShowAll.Visible = True
       '''DoCmd.GoToRecord , , acNewRec
       If DCount("*", "Customer") = 0 Then
            Me.customerno = 1
       Else
        
            Me.customerno = DMax("Customerno", "Customer") + 1
            Me.customerName.Value = " "
       End If
       
    '''Exit_CmdAdd_Click:
        '''Exit Sub
    
    '''Err_CmdAdd_Click:
        '''MsgBox Err.Description
        '''Resume Exit_CmdAdd_Click
    End Sub
    
    Private Sub cmdDelete_Click()
    
    Dim x As Variant
    
    x = MsgBox(" You are abut to delete " & Me.customerName & " from this table - proceed ? ", vbOKCancel)
    
    If x = 1 Then
    
    With myRS
    
    .Delete
    .MoveFirst
    
    
    End With
    
    End If
    
    End Sub

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: How to delete current record in bounded form?

    Have you set myRS ?
    If not then you will get the error message 91...

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: How to delete current record in bounded form?

    Quote Originally Posted by Ecniv
    Have you set myRS ?
    If not then you will get the error message 91...
    Thank u for u reply. could u tell me how to set myRS ?Thanks

  4. #4
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: How to delete current record in bounded form?

    Private Sub cmdDelete_Click()

    Dim x As Variant

    x = MsgBox(" You are abut to delete " & Me.customerName & " from this table - proceed ? ", vbOKCancel)

    If x = 1 Then
    With myRS
    .Delete
    .MoveFirst
    End With
    End If
    End Sub
    /\ you put it in your delete code.. but I don't think you set it to anything (or should it be the recordset on the form?)

    DAO:
    set rst = dbengine(0)(0).openrecordset("table or sqlstatement")
    set rst = currentdb.openrecordset("table or sqlstatement")

    ADO:
    set rst = new adodb.recordset
    strsql ="sql statement"
    rst.open strsql,currentproject.connection,2,3,1 'dynamic, optimistic, adcmdtext
    'or
    strsql ="table"
    rst.open strsql,currentproject.connection,2,3,adcmdtable 'dynamic, optimistic, adcmdtable

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

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