On a form called opportunity I have a combobox called cmbCompanyName to select a company name from a table called Company. This is the first part of my cascade.
The cmbCompanyName has three columns.
Col 0 is the CompanyID, which is hidden.
Col 1 is the CompanayName, which is populated to the form
Col 2 is the CompanyCity, which is populated using a different part of the form using the control =[cmbCompanyName].[Column](2)
All of this works correctly.
The second part of my cascade cmbPoCLastName looks at another table called Contacts and should take the CompanyName from cmbCompanyName to filter my choices.
cmbPoCLastName uses the following query
SELECT Contacts.Company, Contacts.[Last Name], Contacts.[First Name], Contacts.[E-mail Address], Contacts.[Business Phone]
FROM Contacts
WHERE (((Contacts.Company)=[Forms]![Opportunity]![cmbCompanyName]));
To support my cascasde, cmbCompanyName requeries cmbPoCLastName upon update.
Private Sub cmbCompanyName_AfterUpdate()
cmbPoCLastName.Requery
End Sub
All of this result in nothing showing up in the second part of my cascade.
I believe the issue is cmbPoCLastName is filtered by the hidden CompanyID. I cannot figure out how to force this query to look at the company name vs. the ID number.
Thanks.
Based on the first comment made by #June7, I reworked my tables to use CompanyID to related them to one another. I had previously used CompanyID in some tables and CompanyName in others.
Related
I have a couple of tables in my database.
workout_moves - ID, workout Type, Exercise, Reps
session_moves - ID, Exercise(from workout_moves table), Weight, Notes
I have created a form called workout session which has created a subform for the session_moves table.
The session_moves subform looks like this :
This is fine -but when I select my exercise from the list, I want it to autopopulate the associated Reps value from the workout_moves table rather than forcing me to pick from the list, which is not quite what I would like.
As you can see in the workout_moves table, each exercise is matched to a reps column so this should be pretty easy:
I just cannot work out what the "Row Source" should be for the Reps column in this form in order to auto pull in the data associated with the selection in the Exercise column. Please help.
Set the control source to
=Dlookup("Reps";"workout_moves";"[workout Type] = '" & Nz(cboExercise;"") & "'")
in the Reps control. cboExercise is the controlname of the exercise combobox.
Think about changing foreignkey in table session_moves from Exercises to ID (use primarykeys as foreignkeys).
I have a table named "customers", and a table named "cases". These relate to real estate transactions. On the table "cases" I have a field for "other party", which lets you enter a new customer or pick from an existing one if we have already had that person in our database from a different transaction.
I have created a form with a listbox so I can search all the case records via the customer and other party fields (I also show some other info about the case but am not needing to search that info). In formview the listbox shows the customer name, but only shows the ID number for the other party. When I go to the rowsource, buildevent, and see the query in datasheet view, the records display the way I want them to -by name, not showing ID numbers.
Why won't it display correctly on the listbox??? Please help! I have spent way to many hours trying to figure this out :( This is my first time using access and I am just figuring it out as I go.
this is the SQL from the query in the listbox rowsource:
SELECT Query3.Customers.ID, Query3.[Last Name], Query3.[First Name], Query3.[Other Party], Query3.[Property Address], Query3.[Assigned To], Query3.Lawyer FROM Query3;
and this is the SQL from Query3:
PARAMETERS [ [forms]]![FRM_SearchMulti]![SrchText] Text ( 255 );
SELECT CasesALL.*
FROM CasesALL
WHERE (((CasesALL.[Last Name]) Like "*" & [forms]![FRM_SearchMulti]![SrchText] & "*")) OR (((CasesALL.[First Name]) Like "*" & [forms]![FRM_SearchMulti]![SrchText] & "*")) OR (((CasesALL.[Other Party]) Like "*" & [forms]![FRM_SearchMulti]![SrchText] & "*"));
Listboxes and combo boxes have a hidden column feature, usually a primary/foreign key of underlying table. Users generally do not know which primary key they should pick, hence the connecting name/item displays for their selection. Your situation sounds like the key is not being hidden but displaying and with two columns designated, you do not see the Other Party field.
To fix, under Property Sheet / Format Tab of the listbox, adjust Column Count and corresponding Column Widths according to your query (i.e., recordsource of listbox). As shown below the first column of query is hidden with 0 inches of display while the next two fields will display at 2 inches:
Column Count: 3
Column Widths: 0"; 2"; 2"
...
List Width: 4"
Be sure column widths add up to your List Width or there will be cut-offs. Also, inches are automatically added when you enter numbers. Finally, do note the data value of the listbox will be whatever is designated in Bound Column under Property Sheet / Data tab:
Bound Column: 1
Usually, the bound column is the hidden field or it wouldn't be hidden or used!
You probably miss to set columnwidth(s) of the listbox to: 0
I'm working on a small little project, at the moment just a test for a larger project, but I've hit a block that I can't find a solution too.
I have a list of items in a table, and they contain information such as the item name and the price. I have another table with sales. I have a form that will allow you to select a item name, however, then I would like the rest of the form to be auto-filled with information from the items table.
I can make a message box appear when the item name field has been changed, however, through my searching, I am unable to find a way to search the items table for the value of the field, then read the price value, then insert the price value into a field in this form.
First table "items":
itemname: text
price: currency
Second Table "sales":
itemname: text
price: currency
date: time/date
I hope I have explained myself well enough, if not, just ask and I will try to clarify.
Have a look at the Northwind datatabase (northwind.mdb) that ships with Access. They have several examples of how to update a form based upon a combobox changing values.
Also, you might want to look at the table design in the Northwind Database as well. Generally speaking, it is a bad idea to use the product name as the key field in both of your tables. What will happen (and it will eventually) is that the product name is going to change for one of the products and you'll have to update all of the tables that reference that product name.
The better design is to use a key field (I'd recommend an AutonumberField) in your products table and then reference the key field in the sales table. This way, if the product name changes you only have to make the change in one location, not many.
Here's a sample table layout to illustrate my point:
Table Items:
ItemID (Autonumber - Primary Key on the table)
ItemName (Text - Name of product)
Price (Currency)
Table: Sales
ItemID (Integer - Foreign Key to Items.ItemID)
Quantity (Integer - # of units ordered)
Price (Currency)
OrderDate (Date/Time)
Most answers here are posting way too much code and all kinds of SQL statements. As such, these answers are creating world poverty.
The most simple approach is to let the wizard build a combo box on your form to select a given item. This combo box will thus based on the items table. The first column of the combo box will be the PK (autonumber ID) of the items table. This combo box will thus be bound to the ItemID column in sales. The wizard will also “hide” the id, but you WANT to include the other columns in this combo box such as price etc. And you likely should have the 2nd column of this combo box the description of the item from the item table. As noted, you ALSO want to include the price column.
Thus, after you select a item, then to have auto matic fill out the price column, use this code:
This code goes in the AFTER update event of the item combo box:
Me.Price = me.ItemComboBox.column(2)
So when you select a item, the price field will to auto filled for you. And note how you only had to write one line of code.
So all of this can be done using built in wizards and one line of code.
Add an event procedure (code builder) to the dropdown box's onchange event. Right click the dropdown in design view and choose properties. then on the event tab in the properties window click in the on change line and click the '...' button.
In the code for this event you'll need to query the DB (using the dropdown box's index or ID field) to pull the items details into a recordset. The query would look somethign like
"SELECT * FROM Items WHERE ItemID = " & dropdownboxname.value
theres plenty of examples of how to do this on the web
Then you can update the various textboxes in the form with the required fields in the recordset. again theres plenty of examples of this on the web
EDIT:in response to comments below
you'll need to do somethign along the lines of...
Dim rsItems AS DAO.Recordset
Set rsItems = CurrentDB.OpenRecordset("SELECT * FROM Items WHERE ItemID = " & dropdownboxname.value)
If not rsItems.EOF Then
textbox1.text = rsItems![fieldname1]
textbox2.text = rsItems![fieldname2]
end if
Set rsItems = nothing
let me know if thats any help ;-)
I'm trying to follow Microsoft's example on how to add an "All" option to a ComboBox in Microsoft Access, but their article does not do an adequate job of providing guidance, aside from specifying the code.
What I'm trying to do is build a form that allows a user to select an option from a ComboBox (the options are generated from records in a table), and then build a report filtered based on the user's selected option. The ComboBox consists of 2 columns: the primary key/ID of the records and their displayable names.
I can't understand the VBA code Microsoft provides enough to figure out what is going on, but I would like the "All" option in my ComboBox to either have a blank primary key/ID, or one that = 0. That isn't the case, as selecting the "All" option when using the form results in the error message "The value you entered isn't valid for this field". This leads me to believe that the "All" text is getting filled into the primary key/ID column instead of the display column. The example instructs me to assign the display column number as the "Tag" property of the ComboBox - and in this case, my display column number is 2. However, this (and pretty much any other value I add) results in the aforementioned error message.
Any idea if Microsoft's example is even applicable to my case, or do I need to adjust their code somehow?
Check the Control Source property of your combo box. Sounds like it may be bound to a field in the form's record source. If you make it an unbound control (nothing in the Control Source property) you should be able to select any item from the combo's Row Source without Access complaining at you.
Say your combo's Row Source is a query like this:
SELECT id, disp_name
FROM YourTable
ORDER BY disp_name;
You can add an "all" row with a UNION query:
SELECT id, disp_name
FROM YourTable
UNION ALL
SELECT TOP 1 0, "**ALL**"
FROM AnyTable
ORDER BY disp_name;
AnyTable can be just that. If you happen to have a table which contains only a single row, use that one ... and you wouldn't even need the TOP 1 part. Just try not to use some ReallyBigTable as AnyTable.
Edit: Actually some ReallyBigTable would be fine if it has a primary key or other unique field which you can use in a WHERE clause to retrieve a single row:
SELECT id, disp_name
FROM YourTable
UNION ALL
SELECT 0, "**ALL**"
FROM ReallyBigTable
WHERE pk_field = 1
ORDER BY disp_name;
UNION ALL will return all combined rows. If you have any duplicate rows, you can thin them out by using just UNION instead of UNION ALL.
I've been assigned the task to design a temporary customer tracking system in MS Access 2007 (sheeeesh!). The tables and relationships have all been setup successfully. But I'm running into a minor problem while trying to design the data entry form for one table... Here's a bit of explanation first.
The screen contains 3 dropdown boxes (apart from other fields).
1st dropdown
The first dropdown (cboMarket) represents the Market lets users select between 2 options:
Domestic
International
Since the first dropdown contains only 2 items I didn't bother making a table for it. I added them as pre-defined list items.
2nd dropdown
Once the user makes a selection in this one, the second dropdown (cboLeadCategory) loads up a list of Lead Categories, namely, Fairs & Exhibitions, Agents, Press Ads, Online Ads etc. Different sets of lead categories are utilized for the 2 markets. Hence this box is dependent on the 1st one.
Structure of the bound table, named Lead_Cateogries for the 2nd combo is:
ID Autonumber
Lead_Type TEXT <- actually a list that takes up Domestic or International
Lead_Category_Name TEXT
3rd dropdown
And based on the choice of category in the 2nd one, the third one (cboLeadSource) is supposed to display a pre-defined set of lead sources belonging to the particular category.
Table is named Lead_Sources and the structure is:
ID Autonumber
Lead_Category NUMBER <- related to ID of Lead Categories table
Lead_Source TEXT
When I make the selection in the 1st dropdown, the AfterUpdate event of the combo is called, which instructs the 2nd dropdown to load contents:
Private Sub cboMarket_AfterUpdate()
Me![cboLead_Category].Requery
End Sub
The Row Source of the 2nd combo contains a query:
SELECT Lead_Categories.ID, Lead_Categories.Lead_Category_Name
FROM Lead_Categories
WHERE Lead_Categories.Lead_Type=[cboMarket]
ORDER BY Lead_Categories.Lead_Category_Name;
The AfterUpdate event of 2nd combo is:
Private Sub cboLeadCategory_AfterUpdate()
Me![cboLeadSource].Requery
End Sub
The Row Source of 3rd combo contains:
SELECT Leads_Sources.ID, Leads_Sources.Lead_Source
FROM Leads_Sources
WHERE [Lead_Sources].[Lead_Category]=[Lead_Categories].[ID]
ORDER BY Leads_Sources.Lead_Source;
Problem
When I select Market type from cboMarket, the 2nd combo cboLeadCategory loads up the appropriate Categories without a hitch.
But when I select a particular Category from it, instead of the 3rd combo loading the lead source names, a modal dialog is displayed asking me to Enter a Parameter.
alt text http://img163.imageshack.us/img163/184/enterparamprompt.png
When I enter anything into this prompt (valid or invalid data), I get yet another prompt:
alt text http://img52.imageshack.us/img52/8065/enterparamprompt2.png
Why is this happening? Why isn't the 3rd box loading the source names as desired. Can any one please shed some light on where I am going wrong?
Thanks,
m^e
===================================================
UPDATE
I found a glitch in the query for the 3rd combo.. It wasn't matching up with the value of the second combo. I fixed it and now the query stands at:
SELECT Leads_Sources.ID, Leads_Sources.Lead_Source
FROM Leads_Sources
WHERE (((Leads_Sources.Lead_Category)=[cboLead_Category]))
ORDER BY Leads_Sources.Lead_Source;
Those nasty Enter Param prompts are GONE!!! However, the 3rd combo still stubbornly refuses to load any values. Any ideas?
Never mind. Found the fix. The BoundColumn property of the second combo wasn't set to the correct column. Hence the selection values in it were incorrect and the 3rd combo wasn't able to refer to the linked table properly (with the correct index).
Job done :)
Thanks to all who may have taken time out to review the problem.