Problems with writing data from combo box

Rofey

New member
Local time
Today, 19:20
Joined
Aug 6, 2005
Messages
9
OK, I've tried everything I can think of with this combo box. I've searched the internet for days, even bought some big fat Access reference books and read them cover-to-cover, but I still can't get my database to do what I want. This newbie would *really* appreciate some help...

I am trying to create a database which I can use to store client’s advertising expenses. I currently have three tables: tblListings (which stores basic information about each client, with the field ListingID as the primary key); Advertising Rates (which stores the different types of advertising products and their prices, with the field ProductNumber as the primary key); and tblAdvertisingExpenses (which stores each “order” of an advertising product, including the client’s ListingID as a foreign key, date, the type of advertising, and the total cost - the primary key is an auto-numbered field called OrderNumber).

I have a main form called frmListings, which displays the client’s information from the tblListings table, and includes a subform. I wanted the subform to show only the advertising expenses corresponding to the ListingID (ie. client) displayed on the main form, so I based the subform on a query which displays all records from tblAdvertisingExpenses with a ListingID that matches the ListingID displayed from tblListings. So far so good - the records displayed in the subform change correctly when the record in the main form changes.

The subform returns info from the following fields in the tblAdvertisingExpenses table: Date, ProductNumber, and TotalPrice. I want users to be able to select a type of advertising from a combo box on the subform, which looks up the ProductNumber and Cost from another table (tblAdvertisingRates), and then writes the ProductNumber for that type of advertising to the ProductNumber field of tblAdvertisingExpenses, and writes the corresponding Cost to the TotalPrice field of tblAdvertisingExpenses (and the corresponding controls on the subform). The reason I want to write the Cost from tblAdvertisingRates to tblAdvertisingExpenses is so that I can update rates for types of advertising in the future, without having the change cascade through records where the old price has already been paid for the advertising.

My problem is: a) how to get the combo box to write these various values to other controls on the form, and b) how to write the same values to fields on the subform’s underlying record source.

I’ve tried having the combo box look up all the fields from the underlying table (hiding all except the description of the advertising) and setting the bound column to the field with the price. However, the price is not the uniquely identifying field, and the combo box only writes to the TotalPrice control if all the advertising options in the list have a different price.

Sorry if this is terribly confusing. I can provide more specific details (and screen captures) of the tables, queries, forms, and relationships (if I haven’t provided enough specific details already), and would really appreciate any help that anyone can provide. Help?!
 
Rofey,

The combobox can only be "bound" to one field.

You can however use its BeforeUpdate event and do the following:

Me.SomeField = Me.YourCombo.Column(1)
Me.SomeOtherField = Me.YourCombo.Column(2)

The indexes for the .Column start at 0. The second column is 1.

hth,
Wayne
 
I believe WayneRyan meant the AfterUpdate event.
 
RuralGuy,

Interesting point.

I generally use the AfterUpdate event to trigger activities.

For an unbound control, it doesn't make a difference at all - there's no
underlying data to save.

For bound controls like this combo, I still don't see a lot of difference.

If you copied the other columns of the combo to their respective bound
controls BEFORE updating the underlying data - Fine.

If you copied the other columns of the combo to their respective bound
controls AFTER updating the underlying data - Fine.

I think that only subtle error handling could come into play. Or possibly the
use of something like .OldValue

Hope to hear some thoughts on this from you and others ...

Wayne
 
On further reflection you are probably correct in that it makes no difference in this case whether you use the BeforeUpdate or AfterUpdate event. If updating could actually generate an error then it could make a difference. I've always used the AfterUpdate event since the cbo should be stable at that point.
 
Thanks guys, that worked brilliantly. Much appreciated!
 

Users who are viewing this thread

Back
Top Bottom