Solved

Getting DropDown to Work

Posted on 2010-11-11
9
276 Views
Last Modified: 2012-05-10
I have made dozens of these dropdowns on forms. For some reason I can't get this one to work.
Basically, I want to choose the name from the dropdown list, and have it populate the form DropDown.mdb
0
Comment
Question by:4charity
  • 4
  • 4
9 Comments
 
LVL 7

Expert Comment

by:shaydie
Comment Utility
Your dropdown is an unbound control and there are no events.. If you just set the combo box control to InsuredName it will select the correct record.
DropDown.mdb
0
 

Author Comment

by:4charity
Comment Utility
I changed the control source on the combo box to InsuredName. It chanes the insured name, but not the rest of the controls.
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
Comment Utility
Based on the limited textboxes on the form change the rowsource for the listbox to

SELECT i.InsuredName, d.InsuredPrimaryContact, d.InsuredEmail, d.InsuredPhone FROM tblInsuredName as i, tblInsureDetails as d WHERE i.InsuredID = d.InsuredID

So the query for the combo here returns the name and associated contact - run this query individually so you can see what it produces.

Ensure number of columns (property is ColumnCount) is set to 4 in the combo

then on the afterupdate you reference the value to the textboxes like this

Private Sub cboInsuredName_AfterUpdate()
    Me.InsuredName = cboInsuredName.Column(0)
    Me.InsuredPrimaryContact = cboInsuredName.Column(1)
    Me.InsuredEmail = cboInsuredName.Column(2)
    Me.InsuredPhone = cboInsuredName.Column(3)
End Sub


This will then take the values from the combo and populate the form
0
 

Author Comment

by:4charity
Comment Utility
@rockiroads:

Could I also add a filter here, instead? If so, what would be the best way to do that?
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 65

Assisted Solution

by:rockiroads
rockiroads earned 500 total points
Comment Utility
What would be better though if you wanted to add more columns and maybe use the id for other things is like this

The rowsource for the combo should be

SELECT InsuredID, InsuredName FROM tblInsuredName

Column count is 2, but column width is something like this  "0;2.54". Reason for this is we hide the first column, no need to show the id.

Then on the afterupdate event you have the id so you can read the table(s) and do whatever

Private Sub cboInsuredName_AfterUpdate()
    dim rs as dao.recordset

    set rs=currentdb.openrecordset("select * from tblInsureDetails where insuredid = " & cboInsuredName.value)
   
    Me.InsuredPrimaryContact = rs!InsuredPrimaryContact
    Me.InsuredEmail = rs!InsuredEmail
    Me.InsuredPhone = rs!InsuredPhone

    'etc

    rs.close
    set rs=nothing
End Sub
0
 
LVL 65

Expert Comment

by:rockiroads
Comment Utility
>> Could I also add a filter here, instead? If so, what would be the best way to do that?

I am assuming filtering the combo? Well yes you can. What do you want to filter on? Take for example the name. You could introduce a textbox and a button over it
eg

txtFilter and cmdFilter

then on the click update the rowsource
eg

private sub cmdFilter_Click
    if trim(nz(Me.txtFilter,"")) = "" then
        msgbox "It helps if you enter something"
    else
        cboInsuredName.rowsource = "SELECT .... FROM ... WHERE InsuredName LIKE '*" & Me.txtFilter & "*'"
    end if
end sub


I left the query above like that as I do not know which approach you would like to take but essentially its the WHERE part

if the combo doesnt refesh add this after setting the rowsource

cboInsuredName.Requery


0
 

Author Comment

by:4charity
Comment Utility
OK, not to overthink this, I looked back at my past posts, and came up with this one simple line of code:

Me.Filter = "[InsuredID]= " & Me.cboInsuredName
0
 

Author Closing Comment

by:4charity
Comment Utility
OK, not to overthink this, I looked back at my past posts, and came up with this one simple line of code:

Me.Filter = "[InsuredID]= " & Me.cboInsuredName
0
 
LVL 65

Expert Comment

by:rockiroads
Comment Utility
Ah, I thought it was the combo you wanted to filter and not the form.  Remember to use FilterOn to toggle between filtering and not
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

763 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

11 Experts available now in Live!

Get 1:1 Help Now