Listbox dbl click

G

Guest

Would someone be able to direct me to an article or an answer to how to dbl
clk on a record in a subform list box and have it open the record in the
parent form OrdersWDetails form.
If more info is needed the following doesn't work OrderID is Number:
Private Sub List0_DblClick(Cancel As Integer)
Dim stDocName As String
Dim stLinkCriteria As String
'need to get this to open record clicked on don't know if it is DLookup or ??
'stDocName = Me.OrderID.OrdersWDetails
DoCmd.OpenForm stDocName, , , stLinkCriteria

End Sub
Thanks!
 
D

Dirk Goldgar

lmv said:
Would someone be able to direct me to an article or an answer to how
to dbl clk on a record in a subform list box and have it open the
record in the parent form OrdersWDetails form.
If more info is needed the following doesn't work OrderID is Number:
Private Sub List0_DblClick(Cancel As Integer)
Dim stDocName As String
Dim stLinkCriteria As String
'need to get this to open record clicked on don't know if it is
DLookup or ?? 'stDocName = Me.OrderID.OrdersWDetails
DoCmd.OpenForm stDocName, , , stLinkCriteria

End Sub

I'm not sure I have this straight, so please check my understanding:

You have a main form named "OrdersWDetails" -- yes?

This form displays records containing a numeric OrderID field -- yes?

The OrderID field is a unique key to the records displayed by the main
form -- yes?

On that form, there's a subform -- yes?

On that subform, there's a list box named "List0" -- yes?

The list box's bound column holds OrderID values -- yes?

*IF* all that is true, then you can probably use code like this:

'----- start of suggested code -----
Private Sub List0_DblClick(Cancel As Integer)

Dim frm As Form

Set frm = Me.Parent

With frm.RecordsetClone
.FindFirst "OrderID = " & Me!List0
If .NoMatch Then
MsgBox "Order not found!"
Else
frm.Bookmark = .Bookmark
End If
End With

Set frm = Nothing

End Sub

'----- end of suggested code -----
 
G

Guest

You have a main form named "OrdersWDetails" -- yes?
YES
This form displays records containing a numeric OrderID field -- yes?
YES (OrderID is not a visible field)
The OrderID field is a unique key to the records displayed by the main
form -- yes? YES
On that form, there's a subform -- yes? YES
On that subform, there's a list box named "List0" -- yes? YES
The list box's bound column holds OrderID values -- yes?
YES
SELECT Orders.OrderID, Orders.OrderDate, Orders.PurchaseOrderNumber,
qrySupplierIDLookup.SupplierName, Orders.RequestedBy FROM Orders LEFT JOIN
qrySupplierIDLookup ON Orders.SupplierID = qrySupplierIDLookup.SupplierID
ORDER BY Orders.PurchaseOrderNumber;
5 COLUMNS
0";0.7";0.8";2";0.7"

I tried the code as suggested and got Runtime Error 2452 invalid referance
to the parent property
Set frm = Me.Parent

I don't know what to try to fix it.
 
D

Dirk Goldgar

lmv said:
I tried the code as suggested and got Runtime Error 2452 invalid
referance to the parent property
Set frm = Me.Parent

You should only get that error if the code is not executing on a
subform. Are you *sure* your listbox is on a subform, and not on the
main form? A subform, in this sense, is one that is displayed in a
subform control on the parent form -- not just a standalone form that is
related to the main form somehow.
 
G

Guest

No I am not sure... but now I think (from your questions) it is on the main
form...
It is an unbound list box on a tab
tabSelectTransaction

Sorry, so can dbl clicking the item in the list open it within the main form?
lmv
 
D

Dirk Goldgar

lmv said:
No I am not sure... but now I think (from your questions) it is on
the main form...
It is an unbound list box on a tab
tabSelectTransaction

Sorry, so can dbl clicking the item in the list open it within the
main form?

Sure, it's even easier. Just change the code as follows:

'----- start of suggested code -----
Private Sub List0_DblClick(Cancel As Integer)

With Me.RecordsetClone
.FindFirst "OrderID = " & Me!List0
If .NoMatch Then
MsgBox "Order not found!"
Else
Me.Bookmark = .Bookmark
End If
End With

End Sub
'----- end of suggested code -----
 
G

Guest

PERFECT... almost can you tell me how to send the focus back to:
tabOrderDetails

thank you! :~)
 
D

Dirk Goldgar

lmv said:
PERFECT... almost can you tell me how to send the focus back to:
tabOrderDetails

Is tabOrderDetails a tab control, or a page of a tab control?

You could try this and see if it works:

Me.tabOrderDetails.SetFocus

You'd insert that line in the code after the With ... End With block,
before the End Sub line.
 
G

Guest

NOW it is PERFECT!
thanks!

Dirk Goldgar said:
Is tabOrderDetails a tab control, or a page of a tab control?

You could try this and see if it works:

Me.tabOrderDetails.SetFocus

You'd insert that line in the code after the With ... End With block,
before the End Sub line.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top