Results 1 to 2 of 2
  1. #1
    Join Date
    May 2004
    Posts
    1

    Unhappy Unanswered: "No Current Record"

    I've got a form displaying my main records with a nested subform displaying related screenshots one-at-a-time. I want my users to be able to delete screenshots from the screenshots table, and I've coded a button to allow them to do so.

    Unfortunately, after each deletion I get a "No Current Record" error but all attempts to force the app to move the current record after deletion have failed. Can anyone provide advice or an alternative method?

    Thank you SO much - this has been frustrating me for days!!!

    Code:
    Private Sub cmd_Delete_Click()
    On Error GoTo Err_cmd_Delete_Click
    
        deletingRecord = True
        DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70    'selects an item
        DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70    'deletes an item
        deletingRecord = False
     
    Exit_cmd_Delete_Click:
        Exit Sub
    
    Err_cmd_Delete_Click:
        MsgBox Err.Description
        Resume Exit_cmd_Delete_Click
    End Sub
    
    Public Sub checkCurrentRecord(Optional addRecord As Boolean = False, Optional delRecord As Boolean = False)
    'This subroutine checks to see how many records exist and disable/enable navigation as appropriate.
        
        If addRecord <> True Then
            Dim rst As DAO.Recordset
            
            'If the current record is invalid, jump to a valid one.
            If Me.CurrentRecord > Me.Recordset.RecordCount Then
                MsgBox "CurrentRecord: " & Me.CurrentRecord & " RecordCount:" & Me.Recordset.RecordCount
                'Do Not disable controls here!
                Exit Sub
            End If
            
            With Me.RecordsetClone
            
                'Update the tracking label
                label_recordcount.Caption = "Screenshots: Image " & Me.CurrentRecord & " of " & .RecordCount
                    
                'If there is more than one record ----------------------------------
                If .RecordCount > 1 Then
            
                    'make sure all non-nav controls are enabled
                    imgCaption.Enabled = True
                    combo_imgOrigin.Enabled = True
                    cmd_Delete.Enabled = True
                    cmd_replace.Enabled = True
            
                    'If we've deleted the last record, then our pointers are messed up.
                    If Me.CurrentRecord > .RecordCount Then
                        Set rst = Me.RecordsetClone
                        rst.MoveFirst
                        Me.Bookmark = rst.Bookmark
                    Else
                        .Bookmark = Me.Bookmark
                        Me.RecordsetClone.MoveLast 'This is to force a recalculation
                    End If
                    
                    'We don't want people creating new records with the Next button.
                    'Each record must be associated with an uploaded file.
                    If Me.CurrentRecord = .RecordCount Then
                        If cmd_prev.Enabled Then
                            cmd_prev.SetFocus
                        Else
                            btn_Upload.SetFocus
                        End If
                        'disable Next
                        cmd_Next.Enabled = False
                    Else
                        'Next is enabled if this is not the last entry in the set.
                        cmd_Next.Enabled = True
                    End If
                    
                    'If we're on the first record, disable the Prev. Button
                    If Me.CurrentRecord < 2 Then
                        
                        'Shift focus where appropriate
                        If cmd_Next.Enabled = True Then
                            cmd_Next.SetFocus
                        Else
                            btn_Upload.SetFocus
                        End If
                        'Disable previous
                        cmd_prev.Enabled = False
                    Else
                        cmd_prev.Enabled = True
                    End If
                    
                Else
                'There are no records, or there is only one record. ---------
                    btn_Upload.SetFocus         'Move focus away from navs
                    cmd_Next.Enabled = False    'Disable navs
                    cmd_prev.Enabled = False
                    
                    If .RecordCount = 0 Then    'If there are no records
                        label_recordcount.Caption = "No Screenshots Found for this NPC"  'special case
                        'disable controls that might inadvertently create a new record
                        imgCaption.Enabled = False
                        combo_imgOrigin.Enabled = False
                        'disable record delete/edit
                        cmd_Delete.Enabled = False
                        cmd_replace.Enabled = False
                    Else                        ' If there is one record
                        imgCaption.Enabled = True
                        combo_imgOrigin.Enabled = True
                        cmd_Delete.Enabled = True
                        cmd_replace.Enabled = True
                    End If
                End If
                
            End With
        End If
    
    Err_checkCurrentRecord:
        If Err.Description = "No Current Record" Then
            DoCmd.GoToRecord , , acLast
        End If
    
    End Sub
    'Form_Current:------------------------------------------------------------'Displays image in the main control and updates navbuttons/prompts user depending on situation.
    Private Sub Form_Current()
    
        If (deletingRecord <> True) Then
            imageRefresh
            checkCurrentRecord
            'Refresh the subform ------------------------------------------------
            If Me.RecordsetClone.RecordCount > 0 Then
                Me.RecordsetClone.MoveLast
            End If
        Else
            imageRefresh
            'Refresh the subform -------------------------------------------------
            If Me.RecordsetClone.RecordCount > 0 Then
                Me.RecordsetClone.MoveLast
            End If
        End If
        
    End Sub
    
    Private Sub imageRefresh()
    
        Dim img, npcfoldername As String
        Dim filesys
           
        'Build pathname ------------------------------------------------------
    
        If IsNull(txt_imgFilename.Value) Or txt_imgFilename.Value = "" Then
            'If there's no image name available.
            img = currentPath & "nopic.bmp"
        Else
            'create a foldername for this character
            npcfoldername = "NPC_" & txt_CharacterID.Value & "\"
            'Build the full pathname. [Test for exists comes below.]
            img = currentPath & npcfoldername & txt_imgFilename.Value
        End If
        
        'Begin filesystem operations -----------------------------------------
        Set filesys = CreateObject("Scripting.FileSystemObject")
           
        If filesys.FileExists(img) Then
            'if the picture exists, display it
            Image_Display.Picture = img
        Else
            'Picture does not exist. Reset the filename. [Should we delete the record?]
            MsgBox "Image File not found: " & img & vbCrLf & vbCrLf & "Please replace the screenshot or delete this record."
            Image_Display.Picture = currentPath & "nopic.bmp"
        End If
        
    End Sub

  2. #2
    Join Date
    Mar 2004
    Location
    www.scirocco.ca
    Posts
    346
    After deletion either move to the previous record or next record. i.e.

    rst.MoveNext
    If rst.EOF Then
    rst.MoveLast
    End If

    or

    rst.MovePrevious
    If rst.BOF Then
    rst.MoveFirst
    End If
    http://www.scirocco.ca/images/banner...occobanner.gif

    Download for FREE the ADO/DAO Data Controls that makes life EASIER developing database applications in: VB, FoxPro, Access, VC++, .NET etc... Navigate, Add New, Delete, Update, Search, Undo and Save your changes. Supports Disconnected Recordsets and Transactions!

    Or try our Ask An Expert service to answer any of your questions!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •