Hi all,
This may be a tricky one.
I have a listbox (lstResults) with a mouse down event that opens a form. Mouseup closes the form and double click opens yet another form. This serves to allow the user to 'preview' information related to the selected listbox row - prior to opening the record in full, in an unbound form.
I have had some problems getting this to work correctly.
First my code -
This is the event code from the form containing the list box -
Private Sub lstResults_DblClick(Cancel As Integer)
DoCmd.OpenForm "frmPSWork", acNormal, , , , acWindowNormal, Me.lstResults.Value
End Sub
Private Sub lstResults_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
On Error GoTo MouseDownErr:
DoCmd.OpenForm "frmEnqDetails"
MouseDownErr:
Exit Sub
End Sub
Private Sub lstResults_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
DoCmd.Close acForm, "frmEnqDetails", acSaveNo
End Sub
Code from form that opens -
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Open:
Dim ADOrs As ADODB.Recordset
Dim strCriteria As String
Dim MyCaption As Variant
'The Search criteria is field ID equalling the enquiry number
strCriteria = "ID = " & Int(Forms!frmPSUpdate!lstResults.Value) & ""
Set ADOrs = New ADODB.Recordset
ADOrs.ActiveConnection = CurrentProject.Connection
ADOrs.Open "tblEnquiries", , adOpenKeyset, adLockOptimistic, adCmdTable
With ADOrs
'find the Record with ID equalling enquiry number
.Find strCriteria
Me.lblDescription.Caption = .Fields("Description")
.Close
End With
MyCaption = "Enquiry number " & Forms!frmPSUpdate!lstResults.Column(2) & " - Submitted on " & Forms!frmPSUpdate!lstResults.Column(4) & ", by " & Forms!frmPSUpdate!lstResults.Column(3) & "."
Me.Caption = MyCaption
Set ADOrs = Nothing
Err_Open:
End Sub
Description of problem:
The value in the list box does not seem to refresh properly. i.e. When the form is first opened, if the user clicks a row in the listbox nothing is displayed on the form that opens. If they click that row again it works. If they then click a different row, the old information is displayed. If they click the row a second time - the correct information is displayed.
Hopefully that made sense. It seems to be a problem with the lstResults.Value updating/refreshing or perhaps the timing of when the event is fired (eg fired prior to the new selection being registered).
Can anyone offer any advice on how to handle this correctly?
Thanks
Robert
This may be a tricky one.
I have a listbox (lstResults) with a mouse down event that opens a form. Mouseup closes the form and double click opens yet another form. This serves to allow the user to 'preview' information related to the selected listbox row - prior to opening the record in full, in an unbound form.
I have had some problems getting this to work correctly.
First my code -
This is the event code from the form containing the list box -
Private Sub lstResults_DblClick(Cancel As Integer)
DoCmd.OpenForm "frmPSWork", acNormal, , , , acWindowNormal, Me.lstResults.Value
End Sub
Private Sub lstResults_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
On Error GoTo MouseDownErr:
DoCmd.OpenForm "frmEnqDetails"
MouseDownErr:
Exit Sub
End Sub
Private Sub lstResults_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
DoCmd.Close acForm, "frmEnqDetails", acSaveNo
End Sub
Code from form that opens -
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Open:
Dim ADOrs As ADODB.Recordset
Dim strCriteria As String
Dim MyCaption As Variant
'The Search criteria is field ID equalling the enquiry number
strCriteria = "ID = " & Int(Forms!frmPSUpdate!lstResults.Value) & ""
Set ADOrs = New ADODB.Recordset
ADOrs.ActiveConnection = CurrentProject.Connection
ADOrs.Open "tblEnquiries", , adOpenKeyset, adLockOptimistic, adCmdTable
With ADOrs
'find the Record with ID equalling enquiry number
.Find strCriteria
Me.lblDescription.Caption = .Fields("Description")
.Close
End With
MyCaption = "Enquiry number " & Forms!frmPSUpdate!lstResults.Column(2) & " - Submitted on " & Forms!frmPSUpdate!lstResults.Column(4) & ", by " & Forms!frmPSUpdate!lstResults.Column(3) & "."
Me.Caption = MyCaption
Set ADOrs = Nothing
Err_Open:
End Sub
Description of problem:
The value in the list box does not seem to refresh properly. i.e. When the form is first opened, if the user clicks a row in the listbox nothing is displayed on the form that opens. If they click that row again it works. If they then click a different row, the old information is displayed. If they click the row a second time - the correct information is displayed.
Hopefully that made sense. It seems to be a problem with the lstResults.Value updating/refreshing or perhaps the timing of when the event is fired (eg fired prior to the new selection being registered).
Can anyone offer any advice on how to handle this correctly?
Thanks
Robert