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.CompanyNam e, 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.
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.CompanyNam
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.
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. :)
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.CompanyNa me" = "Contacts.CompanyName"?
ASKER
Yes it does.
ASKER
In my unbound list box, I alread bind column one "ExpiresIn60Days.CompanyNa me " of the row source when I look at the data properties. Maybe this will help.
ASKER
Like this:
Private Sub lstboxExpiring_DblClick(Ca ncel As Integer)
On Error GoTo Err_lstboxExpiring_DblClic k
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Contacts"
DoCmd.OpenForm stDocName, , , ExpiresIn60Days.CompanyNam e
Exit_lstboxExpiring_DblCli ck:
Exit Sub
Err_lstboxExpiring_DblClic k:
MsgBox Err.Description
Resume Exit_lstboxExpiring_DblCli ck
End Sub
Private Sub lstboxExpiring_DblClick(Ca
On Error GoTo Err_lstboxExpiring_DblClic
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Contacts"
DoCmd.OpenForm stDocName, , , ExpiresIn60Days.CompanyNam
Exit_lstboxExpiring_DblCli
Exit Sub
Err_lstboxExpiring_DblClic
MsgBox Err.Description
Resume Exit_lstboxExpiring_DblCli
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I get a "variable not defined" in this:
DoCmd.OpenForm stDocName, , , "CompanyName=" & ExpiresIn60Days.CompanyNam e
Specifically on: ExpiresIn60Days
DoCmd.OpenForm stDocName, , , "CompanyName=" & ExpiresIn60Days.CompanyNam
Specifically on: ExpiresIn60Days
ASKER
Private Sub lstboxExpiring_DblClick(Ca ncel As Integer)
On Error GoTo Err_lstboxExpiring_DblClic k
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Contacts"
DoCmd.OpenForm stDocName, , , "CompanyName=" & ExpiresIn60Days.CompanyNam e
Exit_lstboxExpiring_DblCli ck:
Exit Sub
Err_lstboxExpiring_DblClic k:
MsgBox Err.Description
Resume Exit_lstboxExpiring_DblCli ck
End Sub
On Error GoTo Err_lstboxExpiring_DblClic
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Contacts"
DoCmd.OpenForm stDocName, , , "CompanyName=" & ExpiresIn60Days.CompanyNam
Exit_lstboxExpiring_DblCli
Exit Sub
Err_lstboxExpiring_DblClic
MsgBox Err.Description
Resume Exit_lstboxExpiring_DblCli
End Sub
ASKER
I got it! This is what worked:
Private Sub lstboxExpiring_DblClick(Ca ncel As Integer)
On Error GoTo Err_lstboxExpiring_DblClic k
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Contacts"
stLinkCriteria = "CompanyName='" & Forms!MainMenu!lstboxExpir ing & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_lstboxExpiring_DblCli ck:
Exit Sub
Err_lstboxExpiring_DblClic k:
MsgBox Err.Description
Resume Exit_lstboxExpiring_DblCli ck
End Sub
Private Sub lstboxExpiring_DblClick(Ca
On Error GoTo Err_lstboxExpiring_DblClic
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Contacts"
stLinkCriteria = "CompanyName='" & Forms!MainMenu!lstboxExpir
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_lstboxExpiring_DblCli
Exit Sub
Err_lstboxExpiring_DblClic
MsgBox Err.Description
Resume Exit_lstboxExpiring_DblCli
End Sub
ASKER
You got me in the right direction to solve my problem. Thank you very much.
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)?