Results 1 to 7 of 7
  1. #1
    cuddles is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    98

    View Attachment in Unbound listbox

    I have a data entry edit form that is opened when a user double-clicks the data displayed in my unbound listbox. So, when the user double-clicks an item, it opens up the ability to edit that item. My problem is, I have it set to a double click event so the entire row is highlighted. The end-users want the ability to click on the attachment column which houses attachments and view them. I am not sure how to handle this since the entire row is highlighted or selected with the ability to edit it on a double click. I am wondering if there is a way to unhighlight the item and have them double-click on the primary key instead to edit the record, then if they want to view the attachment, I can do a double click event on that to open the attachment? I am posting the code I have now, can anyone help me out?



    Code:
    Option Compare Database
    Option Explicit
    Dim OriginalSQL As String
    Dim LastFilter As String
    
    Private Sub add_Click()
    DoCmd.OpenForm "frmDataEntry", , , , acFormAdd, acDialog
        If (Me.txtfilter <> "") Then 'only set back to original sql if filtering was in progress (that way sorting might stay in place)
            Me.listquality.RowSource = OriginalSQL
            Me.txtfilter = ""
        End If
        Call RequeryList
        Me.listquality = GlobalID
        Me.txtfilter = ""
    End Sub
    Private Sub cmdShowAll_Click()
        Me.listquality.RowSource = OriginalSQL
        Call RequeryList
        Me.listquality.Selected(1) = True
        Me.cmdshowall.Visible = False
        Me.txtfilter = ""
        
    End Sub
    Private Sub Edit_Click()
     DoCmd.OpenForm "frmDataEntry", , , , , acDialog, "AAA"
        Call RequeryList
    End Sub
    
    
        
    Private Sub Form_Load()
    On Error GoTo Err_Form_load
        'set focus to List box so first record is highlighted
        Me.listquality.SetFocus
        Me.listquality.Selected(1) = True
        OriginalSQL = Me.listquality.RowSource
        
    Exit_Form_load:
        Exit Sub
    Err_Form_load:
        MsgBox Err.Description
        Resume Exit_Form_load
        
    
    End Sub
    
    
    Private Sub Listquality_DblClick(cancel As Integer)
        Edit_Click
    End Sub
    Private Sub Listquality_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
        'sort by column mouse cursor is in
        sSortListBox Me.listquality, Button, Shift, x
    End Sub
    Private Sub Listquality_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
        'stops the right click menu from appearing
        If Button = acRightButton Then DoCmd.CancelEvent
    End Sub
    Private Sub RequeryList()
    'requeries the main list box and sets focus back on the listbox
        Me.listquality.Requery
        Me.listquality.SetFocus
    End Sub
    Private Sub txtFilter_AfterUpdate()
        Dim newsql As String
        Dim lastsql As String
        
        lastsql = Me.listquality.RowSource 'hold just in case
        newsql = BuildFilteredSQL(Me.txtfilter, "Quality", OriginalSQL) 'build new query
        Me.listquality.RowSource = newsql
        Call RequeryList
        If (Me.listquality.ListCount <= 1) Then 'revert back if no records returned
            MsgBox "No matching records can be found", vbOKOnly, "Search Failed, Try again"
            Me.listquality.RowSource = lastsql
            Call RequeryList
            Me.txtfilter = LastFilter
        End If
        Me.listquality.Selected(1) = True
        If (Nz(Me.txtfilter, "") <> "") Then  'if filtertext is still there then show "Show all .." button
            Me.cmdshowall.Visible = True
        End If
        
    End Sub
    Private Sub txtFilter_Enter()
        LastFilter = Nz(Me.txtfilter, "")
    End Sub

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    List boxes dont work that way..you only get 1 item.
    NOW, you could put radio buttons above the list ..the default would be OPEN RECORD , radio2 OPEN ATTACHMTS
    Then the dbl-click can take the index and open the right query.

  3. #3
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    how many attachments do you have per item in your list box? is it one or more than one?

    if it's one you can look up the attachment information by using the PK (assuming it's your bound column) from your table or include the field specifics in the query within the list box and retrieve that item using

    me.listquality.selected(1).columns(x)

    where x would be the column in which the file name/information is stored, just remember when referencing a column in a list box or query or table numbering starts at 0, so if visually the file name is in column 3, it will be column 2 when you are referencing the item.

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    p.s. I would set the 'edit' ability to a single click event and the 'open attachment' to a double click if you want to access them through the list box, otherwise you can add a 'view attachment' button after they've opened the record.

  5. #5
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    Show a 2nd list box for attachements.
    When the main record is selected, fill the 2nd list. If 2nd list is dbl-clicked , open it.

  6. #6
    cuddles is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    98
    Ok. I get I can add a 2nd list box and have done that but where would I find code that shows me how to fill in the 2nd list when the main record is selected?

  7. #7
    cuddles is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    98
    I am not able to make this work. It does not update the 2nd list but of course I have tried all sorts of code found online and none of them work.

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

Similar Threads

  1. View attachment name in the form
    By graccess in forum Forms
    Replies: 1
    Last Post: 03-08-2014, 10:32 PM
  2. Populate unbound listbox with VBA
    By usmcgrunt in forum Forms
    Replies: 1
    Last Post: 09-23-2010, 09:11 PM
  3. Access 2007 Attachment and Listbox controls
    By anqoksan in forum Forms
    Replies: 0
    Last Post: 05-15-2010, 11:35 PM
  4. Access 2007 Code Guru please: Unbound Attachment
    By MatthewFF in forum Programming
    Replies: 2
    Last Post: 02-01-2010, 07:31 AM
  5. How To View Hyperlink For Attachment File
    By treyprice in forum Access
    Replies: 0
    Last Post: 07-28-2009, 12:51 PM

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