Solved

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

Posted on 2013-02-04
11
582 Views
Last Modified: 2013-02-04
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.
0
Comment
Question by:jasgot
  • 8
  • 3
11 Comments
 
LVL 84
ID: 38852434
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)?
0
 

Author Comment

by:jasgot
ID: 38852572
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. :)
0
 
LVL 84
ID: 38852609
Does "ExpiresIn60Days.CompanyName" = "Contacts.CompanyName"?
0
 

Author Comment

by:jasgot
ID: 38852886
Yes it does.
0
 

Author Comment

by:jasgot
ID: 38852931
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.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:jasgot
ID: 38852946
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
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 38852971
That's not a valid WHERE clause in the OpenForm method. It should look like this:

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

So the CompanyName is the same, and you now want to open the Contacts form to that record? Is the field "CompanyName" in the Contact form's RecordSource? If it is, then the OpenForm above could be something like this:

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

Author Comment

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

Specifically on: ExpiresIn60Days
0
 

Author Comment

by:jasgot
ID: 38852992
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
0
 

Author Comment

by:jasgot
ID: 38853290
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
0
 

Author Closing Comment

by:jasgot
ID: 38853292
You got me in the right direction to solve my problem. Thank you very much.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now