Results 1 to 6 of 6
  1. #1
    harmankardon is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    6

    No current record.

    Hello all,



    First time poster here, love this site and hopefully I can start contributing someday.

    I have a button in the header of a subform that when clicked brings up an insert file dialog for users to attach BLOBs to a form using an OLE field.

    The problem I am having is tricky. If there are no records in the subform, and I've just opened the parent form, I can click my new attachment button without any problems. But if I add 1 attachment, delete it (so now the subform has 0 records) and then try to click new attachment again I get a "No current record" error, but it doesn't seem to have any affect on anything. I just click OK and it continues on as expected. The same thing happens too when I try to go into design view after adding, deleting and re-adding an attachment.

    I can even seem to trap this error by putting a break point on my first line of code, the error happens before the first line executes.

    The code I am using looks like this:

    Code:
    Private Sub btnNewRecord_Click()
        Dim BytesRead As Variant, BytesWritten As Variant
        Dim Msg As String
        Dim T As Recordset
        Dim source As String
    
        ' Open the BLOB table.
        Me.AllowAdditions = True
        Set T = Me.Recordset
     
        T.AddNew
        T.Fields("REA_NUM") = Me.Parent.Form.REA_Num
            
        ' Move file into record.
        source = modBLOB.getOpenFileName()
        If source <> "" Then
            BytesRead = ReadBLOB(source, T, "Blob")
    
            If (BytesRead < 0) Then
                MsgBox "Error Saving attachment", vbCritical + vbOKOnly, "Error"
            End If    
    
            T.Update
    
        Else
            T.CancelUpdate
        End If
        Me.AllowAdditions = False
    End Sub
    Any ideas? How horrible would it be for me to just suppress the error somehow?

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Where do you open the Recordset? Where/How do you identify(Dim) this database?
    Did you create this code or did you get it from another site?

  3. #3
    harmankardon is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    6
    I did indeed get this code from somewhere else: http://support.microsoft.com/kb/103257

    And it appears that for some reason I removed the code which would identify the database. As far as opening the recordset, it was my understanding that line 9 is what opened the recordset.

    What gets me is that it works fine in any scenario expect for the one I described in my original post.

  4. #4
    harmankardon is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    6
    Ok so I've added the proper code to open the recordset and identify the database. My code now looks like this:

    Code:
    Private Sub btnNewRecord_Click()
        Dim BytesRead As Variant, BytesWritten As Variant
        Dim Msg As String
        Dim T As Recordset
        Dim source As String
        Dim db As Database
    
        ' Open the BLOB table.
        Me.AllowAdditions = True
        Set db = CurrentDb()
        Set T = db.OpenRecordset("REA_BLOB_ATTACHMENTS", dbOpenTable)
     
        T.AddNew
        T.Fields("REA_NUM") = Me.Parent.Form.REA_Num
            
        ' Move file into record.
        source = modBLOB.getOpenFileName()
        If source <> "" Then
            BytesRead = ReadBLOB(source, T, "Blob")
    
            'Msg = "Finished reading """ & source & """"
            'Msg = Msg & Chr$(13) & ".. " & BytesRead & " bytes read."
            'MsgBox Msg, 64, "Copy File"
            If (BytesRead < 0) Then
                MsgBox "Error Saving attachment", vbCritical + vbOKOnly, "Error"
            End If
            
            T.Update
        Else
            T.CancelUpdate
        End If
    
        Me.AllowAdditions = False
    End Sub
    Now I am no longer getting the "No current record" error (Yay!) but I have to click refresh all in the ribbon to see the record in the subform. I'm guessing that's something I can easily call in VBA. Should I also be closing the recordset as well?

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    See this
    http://www.techonthenet.com/access/subforms/refresh.php

    and see if it applies to your situation.

  6. #6
    harmankardon is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    6

    Thanks

    Thanks, you've been a great help!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Report from current record
    By billgyrotech in forum Reports
    Replies: 18
    Last Post: 07-26-2011, 03:39 PM
  2. Current record number
    By turvoll in forum Programming
    Replies: 1
    Last Post: 11-04-2010, 10:09 AM
  3. copy current record to new record
    By er_manojbisht in forum Forms
    Replies: 1
    Last Post: 02-27-2010, 05:31 PM
  4. Replies: 3
    Last Post: 02-13-2008, 09:55 AM
  5. Mailmerge Current Record...
    By oakleyp2 in forum Programming
    Replies: 0
    Last Post: 02-22-2006, 08:08 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
  •  
Other Forums: Microsoft Office Forums