473,399 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Make Fields Autopopulate from a ComboBox Selection based on a Separate Table?

Hello, I'm kind of a newbie with Access (2007) and Visual Basic and am wondering if someone could help me out. I've searched all over for an answer to this and haven't found one that's worked out for me.

I have a form titled "Contracts" which contains all of the information for customer contracts. On the Contracts form there is a combo box linked to a "Customers" table to provide the data for the list of customers in that combo box.

Customer account numbers are kept on the "Customers" form.

I was wondering if there is a way (I would imagine there is) to have a text field populate with a corresponding customer account number on the Contracts form after the Customer is selected from the combo box? Any help would be greatly appreciated, I've been trying to figure this out for days!
Aug 17 '10 #1
9 6420
Jerry Maiapu
259 100+
You can just use inbuilt wizards to do exactly that but anyway try this:
Make sure that there is a common field value (unique-primary key) in combo and the form. (for example employee Id)

imagine that your;
1. combo box is cmboname
2. common Id is EmployeeID

Paste this on the After Update event of the combo box.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmboname_AfterUpdate()
  2.     ' Find the record that matches the control.
  3.     Dim rs As Object
  4.  
  5.     Set rs = Me.Recordset.Clone
  6.     rs.FindFirst "[EmployeeID] = " & str(Nz(Me![cmboname], 0))
  7.     If Not rs.EOF Then Me.Bookmark = rs.Bookmark
  8. end sub
Post back if any query
Aug 18 '10 #2
I received an error when I tried the code you provided...don't I have to point the afterupdate to a textbox to populate it?

I tried using:

Expand|Select|Wrap|Line Numbers
  1. Private Sub ClientName_AfterUpdate()
  2. Me!Text71 = Me!ClientName.Column(2)
  3. End Sub
Which got the account number to generate, however the text field that was populated did not change when switching records. So whenever I updated the combobox on any record that would generate the number for all of the records.

Any other suggestions? You mentioned I could use the built-in wizards to accomplish this, but I have had no luck...
Aug 18 '10 #3
Jerry Maiapu
259 100+
I need to see you record source structure of the forms (sub-form and main form)
Attached your db and post it. I'll see what i can do for you
Aug 18 '10 #4
Thanks again for your reply, sorry it took so long to respond. I can't send out the database (confidentiality reasons), but I have included some screenshots that hopefully help explain my problem.

The first is the clients form, where the three fields I'm dealing with have all the data initially entered in.

The second is the contracts form, which has a combobox to select from client name's that have been listed in the client form. I've added two text fields in hopes to have them generate with the data (account# and meter#), also from the clients form and specifically related to the client that is selected from the combobox.



Aug 23 '10 #5
Jerry Maiapu
259 100+
Sorry I cannot see your screenshots
Aug 24 '10 #6
OldBirdman
675 512MB
I'm not exactly sure what you can or can't do from your screenshots. I am attaching a demo of what I think you can use. I hope it helps
Attached Files
File Type: zip TextBox.zip (28.4 KB, 293 views)
Aug 24 '10 #7
NeoPa
32,556 Expert Mod 16PB
The usual, easier, approach, would be to have a multi-column ComboBox that displays both the ID and the name.

If it's necessary, for some reason, to maintain the name in a separate TextBox control, then it should be unbound and it would be updated by code from the value in the ComboBox (It should be Multi-Column whether or not you intend to display the data as such) from within the AfterUpdate() event procedure of the ComboBox.

Welcome to Bytes!
Aug 24 '10 #8
Jerry Maiapu
259 100+
There is no realtionship specified yet for the tables, nevertheless like Neo says try thsi:


Qute busy right now for further explaination.


Expand|Select|Wrap|Line Numbers
  1. Private Sub Combo27_AfterUpdate()
  2.         Dim rs As Object
  3.  
  4.     Set rs = Me.Recordset.Clone
  5.     rs.FindFirst "[MonthNumber] = " & Str(Nz(Me![Combo27], 0))
  6.     If Not rs.EOF Then Me.Bookmark = rs.Bookmark
  7. End Sub
Aug 24 '10 #9
NeoPa
32,556 Expert Mod 16PB
Jerry:
like Neo says try this:
I'm not sure you followed my point exactly Jerry. The most important part of my point, as I see it, is that when the data is loaded from the table into the ComboBox control, as it has to be anyway to load the IDs, then if it also has the associated names loaded it will always have the data available already, without need for extra resources to manage a recordset of any kind. It would simply be picked up from the ComboBox, which we saw earlier, need only be queried the once at the very start.

I hope this makes it all a little clearer.
Aug 24 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jeff Barry | last post by:
Hi, I wonder if any one can help, I'm pretty new to Access and I can't figure out how to change the contents of a combo box based on a selection I make in another. Let me explain I have a...
0
by: KB | last post by:
I am creatig a database in 2000 where I need to be able to have the users add data and information into lookup tables. That is no problem, I have a form for that, that works fine. This...
1
by: Cassie Pennington | last post by:
I have tried to filter one combo box based on a selection in another combo box, by using the following sample code: tblfield=forms!!. However, the combobox only seems to recognise the first...
2
by: PerryC | last post by:
Scenario: FormA: Field1, Field2 (Field1 is a combo box based on a NameTable w/ Name and phone fields) When users choose Field1 with Name1 (in record1 of NameTable), Field2 will...
1
by: Richard | last post by:
Very typical normal data Table One ------ One.OneID (PK) One.Name One.Description One.TwoID (FK) One.ThreeID (FK) ....
1
by: girjer | last post by:
I want to populate two table fields on a selection of either combo box, list box or any option button. For e.g. When I select 'YES' as an option I want to populate two fields in the table i.e....
2
by: Madmaxrtw | last post by:
What I have is one table (tblXNumber) with a bunch of data numbers in it. For example: 123456 123456.05.02.01 123456.05.02.01.01 etc. Then I have a seperate table with Item names in it...
4
WyvsEyeView
by: WyvsEyeView | last post by:
I am doing the very standard thing of filtering the contents of one combo box based on another combo box. I've done it many times, but always on a main form. Now I'm trying to do it on a datasheet...
1
by: shalskedar | last post by:
In my DB i need to change the value for a Combo Box based on some condition.. These values r retrieved from 1 of the tables(Glass) My Query is in my form 1 of the Combo boxes display these...
7
by: RG360 | last post by:
Hello. I am new in Access and I need assistance from Pro's I have a data entry form from 2 main tables and they have relationships with other tables. My main table only contains Field ID's,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.