Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 12th, 2006, 09:45 AM
Authorized User
 
Join Date: May 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Linking 2 data fields from 1 table

This maybe a beginner question however I can’t seem to link 2 columns from 1 table into 2 sub form combo drop down lists. For example I have a table (Tests) with 2 columns called TestName (text) and ModuleCode (text, i.e. BL01). In the subform (Marks) I have 2 combo boxes for both headings, now I want to select the Testname from the drop down combo box and automatically it should populate the applicable ModuleCode associated to the test and vise versa, is this possible and what would be the best approach to accomplish this?

Thank you in advance for any suggestions.
 
Old May 13th, 2006, 05:37 AM
Authorized User
 
Join Date: May 2006
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Ashfaque
Default

Hi,

There may be various ways to do it. But I find my way is easiest.

I created a db for you for the raised topic but unfortunately I don't see any attachment facility here. Anyhow.

Considering your 2 combo boxes named as CboName & CboModule those are placed on the form, do the following :

1. Delete the rowsource (if u created combo based on query / table)of your second combo box (CboModule) and AfterUpdate event of first combo (i.e. CboName) write down following code lines.

Dim Qst As String
Qst = "SELECT T_Tests.TestName,T_Tests.ModuleCode FROM T_Tests Where T_Tests.TestName='" & Me.CboName & "'"
Me.CboModule.RowSource = Qst
Me.CboModule.SetFocus

2. OnGotFocus event of 2nd combo (CboModule) write following line:

Me.CboModule.DropDown

It works smoothly.

With kind regards,

Ashfaque

N. B. : To make it more productive, do not forget to put DISTINCT clause in your first combo query.
 
Old May 16th, 2006, 11:50 PM
Authorized User
 
Join Date: May 2006
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Ashfaque
Default

aRtware,

I sent you a database file that you requested for.

Please check your email and let me know if it meets your requirement.

Regards,
Ashfaque


 
Old May 18th, 2006, 02:43 PM
Authorized User
 
Join Date: May 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for your example it helps me understand the breakdown by any chance is the same result possible just using a select sql query within the 2 combo fields?
 
Old May 21st, 2006, 11:38 PM
Authorized User
 
Join Date: May 2006
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Ashfaque
Default

MAY BE...
 
Old May 23rd, 2006, 11:14 PM
Authorized User
 
Join Date: Apr 2006
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If I understand your question correctly, its possible to set up a relationship between the 2 tables in your databasehe relationship screen. Then use one fo the 2 drop downs to populate the other data.

For instance for an inventory system user types in an item id number and the form fills in' the item description package size etc.

I dont know if that answers your question or not.

 
Old May 26th, 2006, 10:06 AM
Authorized User
 
Join Date: May 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for all the suggestions I figured out how to get a similar effect using a select statement here is what I did: On the Marks sub form row source of the TestName combo box I used the following,

SELECT training_tests.TestName FROM training_tests GROUP BY training_tests.TestName ORDER BY training_tests.TestName;

Then on the row source of the ModuleCode combo box I used this query,

SELECT training_tests.ModuleCode FROM training_tests WHERE (((training_tests.TestName)=Forms!frm_main_employe e!frm_marks_sub!combo_marks_test_name)) GROUP BY training_tests.ModuleCode ORDER BY training_tests.ModuleCode;

The result gives me the desired effect with the exception that if a user wants to make an adjustment/correction in picking the TestName the appropriate ModuleCode no longer populates with the corrected TestName and therefore the user will have to exit the form and reselect the TestName so that the ModuleCode field would match. If anyone has any suggestions on this please let me know.
 
Old May 28th, 2006, 11:23 PM
Authorized User
 
Join Date: May 2006
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Ashfaque
Default

Glad to know that you achieved what you wanted...

Ashfaque






Similar Threads
Thread Thread Starter Forum Replies Last Post
Linking table Date fields by month wintermute Access VBA 4 April 3rd, 2008 04:35 AM
Need help linking userID fields RJ2001 SQL Server 2000 0 August 8th, 2007 08:33 PM
How to replace pivot table data fields using VBA? rstober Excel VBA 2 August 19th, 2005 06:06 AM
Linking two tables/ Looking up data in one table ashcarrot SQL Language 2 June 24th, 2003 04:07 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.