A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Assigning Data to Multiple Fields with a Combo Box



 
 
Thread Tools Display Modes
  #1  
Old July 20th, 2009, 03:47 PM posted to microsoft.public.access.gettingstarted
SteveH
external usenet poster
 
Posts: 69
Default Assigning Data to Multiple Fields with a Combo Box

I have a form with a combo box that looks up the item number, average cost,
and last cost from the items table. The item number is bound to the field in
the orders table. I would like for it to also populate the average cost and
last cost fields in the order table since those change frequently. How can I
do this? Thanks for any help.
  #2  
Old July 20th, 2009, 05:17 PM posted to microsoft.public.access.gettingstarted
John Spencer
external usenet poster
 
Posts: 7,815
Default Assigning Data to Multiple Fields with a Combo Box

If you have controls on the form bound to an AverageCost and LastCost fields
in the Orders table then you should be able to use the after update event of
the combobox to set the values. Assuming that the combobox has 3 columns
showing in order ItemNumber, AverageCost, and LastCost you would need
something like the following in the afterupdate event of the combobox.

Private Sub ComboboxItems_AfterUpdate()

'Column count is zero-based so first column is column zero
Me.TxtAverageCost = Me.ComboBoxItems.Column(1)
Me.txtLastCost = me.ComboboxItems.Column(2)

End Sub

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

SteveH wrote:
I have a form with a combo box that looks up the item number, average cost,
and last cost from the items table. The item number is bound to the field in
the orders table. I would like for it to also populate the average cost and
last cost fields in the order table since those change frequently. How can I
do this? Thanks for any help.

  #3  
Old July 20th, 2009, 05:51 PM posted to microsoft.public.access.gettingstarted
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Assigning Data to Multiple Fields with a Combo Box

On Mon, 20 Jul 2009 07:47:01 -0700, SteveH
wrote:

I have a form with a combo box that looks up the item number, average cost,
and last cost from the items table. The item number is bound to the field in
the orders table. I would like for it to also populate the average cost and
last cost fields in the order table since those change frequently. How can I
do this? Thanks for any help.


You can put VBA code in the combo box's AfterUpdate event. Include the desired
fields in the combo's rowsource and "push" them into textboxes bound to the
other fields:

Private Sub cboItem_AfterUpdate()
Me!LastCost = cboItem.Column(3)
etc
End Sub

The Column property is zero based so this would copy the *fourth* field in the
combo's row source query.

Do note that storing the *AVERAGE* cost is probably a bad idea - average over
what span? Wouldn't the average change every time the cost changed?
--

John W. Vinson [MVP]
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 01:50 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.