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