Link to home
Start Free TrialLog in
Avatar of jasgot
jasgot

asked on

Ms Access - Need to make a Detail items in a SubForm clickable to another form.

I have a subform that is populated by the union of two queries. The result are displayed in an unbound listbox.

The contents are software license keys and expire dates for software we write for our customers

My desire is to be able to dbl click on an item in the list box and have it take me to the Contact Management Form for the customer in question.

This is the Row Source for my unbound List box:

SELECT ExpiresIn60Days.CompanyName, ExpiresIn60Days.Item AS Product, ExpiresIn60Days.[What's Expiring], ExpiresIn60Days.EXPIRES, ExpiresIn60Days.SerialNo FROM ExpiresIn60Days ORDER BY ExpiresIn60Days.EXPIRES;


I have a button on my main menu that takes me to the Contacts Form, from there I have to select the contact from a drop down list.

This is the button that take me to the Contact Form:
Private Sub EditContacts_Click()
On Error GoTo Err_EditContacts_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "Contacts"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_EditContacts_Click:
    Exit Sub

Err_EditContacts_Click:
    MsgBox Err.Description
    Resume Exit_EditContacts_Click
   
End Sub


And here is the code for the combo box that opens the customer in the Contact Form
Private Sub Combo22_AfterUpdate()
 Dim rs As Object
    Set rs = Me.Recordset.Clone
    rs.FindFirst "[CustNumber] = " & Str(Me![Combo22])
    Me.Bookmark = rs.Bookmark
End Sub


My goal is to click anywhere on the item in the list box, and have it open the contact form with the same customer as who I clicked on in the list box.

Thanks.
Please ask any questions needed to make this work.
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Set the value of strLinkCriteria to the correct CustNumber:

    DoCmd.OpenForm stDocName, , , "[CustNumber]=" & Me.SomeValue

Of course, the Listbox where this code is fired would need to be able to get the value of CustNumber - is that value available somewhere (like on the parent form of that listbox, perhaps)?
Avatar of jasgot
jasgot

ASKER

The customer number comes from that Contacts Table.  Should I add that table to the union I use for the list box? Or is there another way to get that data?

This is my row source for the combo box on the contact form that lets me select the customer:
SELECT Contacts.CompanyName, Contacts.CustNumber, Contacts.ContactPerson FROM Contacts ORDER BY Contacts.CompanyName;

Now that I think about it, the customer number represents ONE of the contact pserons at a given company.  The list box I want to click in is based on the company name only. So I'm not sure how I would select a company name and the have it open the contact form with a customer number. It doesn;t matter which customer number/contact name I use because each contact record show the same licensing info (based on the company)

My union is only editable in SQL, so it will be a challenge for me to add another table without help. Design view agreese with me, SQL view does not. :)
Does "ExpiresIn60Days.CompanyName" = "Contacts.CompanyName"?
Avatar of jasgot

ASKER

Yes it does.
Avatar of jasgot

ASKER

In my unbound list box, I alread bind column one "ExpiresIn60Days.CompanyName " of the row source when I look at the data properties. Maybe this will help.
Avatar of jasgot

ASKER

Like this:
Private Sub lstboxExpiring_DblClick(Cancel As Integer)
On Error GoTo Err_lstboxExpiring_DblClick

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "Contacts"
    DoCmd.OpenForm stDocName, , , ExpiresIn60Days.CompanyName

Exit_lstboxExpiring_DblClick:
    Exit Sub

Err_lstboxExpiring_DblClick:
    MsgBox Err.Description
    Resume Exit_lstboxExpiring_DblClick
End Sub
ASKER CERTIFIED SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jasgot

ASKER

I get a "variable not defined" in this:
DoCmd.OpenForm stDocName, , , "CompanyName=" & ExpiresIn60Days.CompanyName

Specifically on: ExpiresIn60Days
Avatar of jasgot

ASKER

Private Sub lstboxExpiring_DblClick(Cancel As Integer)
On Error GoTo Err_lstboxExpiring_DblClick

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "Contacts"
    DoCmd.OpenForm stDocName, , , "CompanyName=" & ExpiresIn60Days.CompanyName

Exit_lstboxExpiring_DblClick:
    Exit Sub

Err_lstboxExpiring_DblClick:
    MsgBox Err.Description
    Resume Exit_lstboxExpiring_DblClick
End Sub
Avatar of jasgot

ASKER

I got it! This is what worked:

Private Sub lstboxExpiring_DblClick(Cancel As Integer)
On Error GoTo Err_lstboxExpiring_DblClick

    Dim stDocName As String
    Dim stLinkCriteria As String
   
    stDocName = "Contacts"
    stLinkCriteria = "CompanyName='" & Forms!MainMenu!lstboxExpiring & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_lstboxExpiring_DblClick:
    Exit Sub

Err_lstboxExpiring_DblClick:
    MsgBox Err.Description
    Resume Exit_lstboxExpiring_DblClick
End Sub
Avatar of jasgot

ASKER

You got me in the right direction to solve my problem. Thank you very much.