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  dBforums > PC based Database Applications > Microsoft Access > Want Combo-box to populate another field in same form

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
Join Date: Aug 2008
Posts: 25
Want Combo-box to populate another field in same form

Hello,

I have a Product ID field which is a combox whose dropdown displays 2 columns (Product ID Code, Product Name) so the user can select the proper ID based on the name. When selected, only the ID Code displays and writes to the table. I would like the next textfield (Product Name) to populate automatically.

I've tried to add the AfterUpdate on the ProdcutID field to say Me.ProductName = Me.ProductID.Column(1) but this is not working.

Any suggestions?
thanks!
G
Reply With Quote
  #2 (permalink)  
Old
Registered User
 
Join Date: Aug 2008
Posts: 25
Figured this out but thanks anyway!

G
Reply With Quote
  #3 (permalink)  
Old
L33t Helpa Munky
 
Join Date: Nov 2007
Location: Adelaide, South Australia
Posts: 4,049
You could say what you did to fix it. What you are seeking sounds like a bad idea... I hope you "fixed" it in a way that doesn't cause you dramas later on.....
__________________
Owner and Manager of
CypherBYTE, Microsoft Access Development Specialists.
Microsoft Access MCP.
And all around nice guy!


"Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
"...teach a man to code and he'll be frustrated for life! " -- georgev
Reply With Quote
  #4 (permalink)  
Old
Registered User
 
Join Date: Aug 2008
Posts: 25
ha OK I thought I had this fixed but alas no...

I found a way to have my combobox (ProductID) configured so that when a value is selected, it automatically fills in the associated text box (ProductName). The combobox has 2 columns of data (I used the LookupWizard to do this), and I have this code in the Source for the text box: =ProductID.Column(1) in order for the proper name to populate.

This works fine except that the text box value is not writing to the table.

Any ideas why?

thanks!!
Reply With Quote
  #5 (permalink)  
Old
L33t Helpa Munky
 
Join Date: Nov 2007
Location: Adelaide, South Australia
Posts: 4,049
Why: Because it is no longer bound to the field you want it to write to because you changed the source away from the fieldname.

What to do: Restore the Control Source back to ProductName. Write a VBA script to populate the field with the combo box selection:

Code:
Sub ProductID_AfterUpdate()
   Me.ProductName = ProductID.Column(1)
End Sub
This goes in the AfterUpdate [Event Procedure] for the combo box.
__________________
Owner and Manager of
CypherBYTE, Microsoft Access Development Specialists.
Microsoft Access MCP.
And all around nice guy!


"Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
"...teach a man to code and he'll be frustrated for life! " -- georgev
Reply With Quote
  #6 (permalink)  
Old
Registered User
 
Join Date: Aug 2008
Posts: 25
Thanks StarTrekker,

This works great for my combo boxes that have more than 1 row, however, for the DB I am building there is a need to have a form with a combobox with only 1 row (I know this is silly but the form must look EXACTLY like the PDF). I can set the default to display the correct row with setting the Default Value to [DistrictID].[ItemData](0), however, the DistrictName text field only displays when I manually re-select the DistrictID combobox (even though it is already selected at default).

Is there a simple way to have the text field also selected at default, or if not, is there a way to the have the text field DistrictName default to the correct name?

thanks!!
Reply With Quote
  #7 (permalink)  
Old
L33t Helpa Munky
 
Join Date: Nov 2007
Location: Adelaide, South Australia
Posts: 4,049
Quote:
Is there a simple way to have the text field also selected at default, or if not, is there a way to the have the text field DistrictName default to the correct name?
"Simple" is subjective. Someone might find one thing simple and another person might find that same thing challenging.

However, can't you just set the thing via the Default Value property for the text box directly... as in the text value that is the default rather than referring to the items in the combo box?
__________________
Owner and Manager of
CypherBYTE, Microsoft Access Development Specialists.
Microsoft Access MCP.
And all around nice guy!


"Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
"...teach a man to code and he'll be frustrated for life! " -- georgev

Last edited by StarTrekker; 08-20-08 at 23:52.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On