473,836 Members | 1,247 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing record source based on combo box

Teresa Kline
4 New Member
I have a form with a combo box. In the combo box is a list of tables in my database. I want to be able to select a table from my combo box and based on that selection open another form that uses that table as a record source.

I want to use the same form each time but change the record source based on the table I select from my combo box.

Thanks for any help.

Mar 27 '12 #1
8 8764
32,584 Recognized Expert Moderator MVP
That's possible if a little risky, but did you have a question?
Mar 27 '12 #2
Teresa Kline
4 New Member
Yes my question was how do I do this either in VBA or in the form?


Mar 28 '12 #3
32,584 Recognized Expert Moderator MVP
You seem to be missing the point somewhat, but maybe if I answer that question, then you'll understand how a question with more of the basic information included, can yield you a more helpful answer.

The answer to your question is that you design a form that can take any of the tables to be used. You populate a Combo/ListBox with a list of all these tables, and when the form is opened (after selecting an item from the list or from behind a Command Button) you change this form's .RecordSource property to a string value reflecting the name of the chosen table. This change can be done in the Open event procedure of the new form without the form trying to open any previously set record source.

The fact that you're even asking this question at all, leads me to suspect that you have a number of tables with the same (or very similar) design. This is indicative (a strong indicator if not entirely conclusive) of a database design which is not normalised (Database Normalisation and Table Structures). I strongly recommend that you stop now and consider the advisability of proceeding along this course. Unless a database is really quite trivial, normalisation is a must have. Probably the biggest cause of database problems is the lack of these concepts in databases. My advice is certainly that this should be dealt with as a matter of priority.

For now though, this is an answer (albeit fairly basically stated without named references) to your question.
Mar 28 '12 #4
Teresa Kline
4 New Member
I'm sorry that I didn't give enough information in my original post...I have a process that runs and selects a group of people based on their location from SAP. The selection is then written to a table in SAP that is named for example: tbllocation1033 02012. Then a second query is run for a different location and that table is named...tblloca tion203302012.. and so on. At this point various users will need to go into the database and update their specific table based on the location they service so I need for them to be able to select a table from the combo box that contains the list of tables in the database and open a standard form for updating but with their selected table. All the fields are the same in every table created and the form contains the same fields as well. The table names however will change and will be deleted and recreated with different locations. there are over a hundred locations possible and the date at the end will change. I have created a query that will pull the list of tables in my database for my combo box...and I have a form but i just can't seem to get the form recordsource to pull the variable from the combo box. Does this make sense?

Thanks so much.

Mar 28 '12 #5
759 Contributor
NeoPa already answer to your "how to" question.
This post is only for more details.
So you have (at least) 3 possibilities:

1) From the main form pass the name of table to the second form using OpenArgs:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenForm "SecondFormName", , , , , , Me.CmbTables
In the second form (_Open event) you will have:
Expand|Select|Wrap|Line Numbers
  1. Me.RecordSource = Me.OpenArgs

2)Also in _Open event (second form) place this code:
Expand|Select|Wrap|Line Numbers
  1. Me.RecordSource = Form_MainFormName.CmbTables
Note please that Form_MainFormNa me is the main form name as you see it in VB editor (Project Explorer) not the name you see in Navigation Pane.

3) Create a Public variable in a normal module:
Expand|Select|Wrap|Line Numbers
  1. Public TableToOpen As String
Assign value to this variable then open the second form:
Expand|Select|Wrap|Line Numbers
  1. TableToOpen = Me.CmbTables
  2. DoCmd.OpenForm "SecondFormName"
Then, under _Open event for the second form:
Expand|Select|Wrap|Line Numbers
  1. Me.RecordSource = TableToOpen
Hope this solve your problem.

And now an answer to your last question:
Does this make sense?
No. Because I can't understand why you run a Make Table query to create a lot of tables then use this tables as Record Sources for forms in your Front End databases. Then I suppose that you run other query (or queries) in order to update the main database.
Why you don't use that Make Table query (of course, as a Select query) as record source for your second form ? And the main database will be updated in that single step.

Of course I can't be sure that yo have not strong reasons to proceed as you proceed.
But I wish to re-advice you to follow the link you see in NeoPa's post.

Good luck !
Mar 28 '12 #6
32,584 Recognized Expert Moderator MVP
Teresa Kline:
Does this make sense?
It's much more of an explanation than before, so is much clearer. Unfortunately, without understanding what SAP means to you I'm still a little unclear, but I recognise the attempt to provide the missing info.

Mihail has already provided more detailed clues as to the sort of approach you'd need. It's still hard to know how much detail to include for you as we don't know how much you understand. Typical questions, as explained in the posts at the top of the Access forum (and most other forums), include the work you have done so far and the names of the objects you're working with. With this info to hand we can pitch an answer so that it's more likely to mean more to you. Explanations including named references that mean something to you are generally a lot easier for you to make sense of.

Normalisation is something that often doesn't hold very true for temporary tables (by which I mean it is less critically necessary and one can be tied to the capabilities of external systems), and I'm guessing these [tblLocation*] tables are just that (If not then you do have a problem). If so, remember to delete them when finished with.

I recommend Mihail's first approach for handling passing the selected table name, but not with positional parameters. Try instead :
Expand|Select|Wrap|Line Numbers
  1. Call DoCmd.OpenForm(FormName:="SecondFormName", OpenArgs:=Me.cboTables)
For the Open event of the new form use :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2.     Me.RecordSource = Me.OpenArgs
  3. End Sub
Clearly, you will need to replace "SecondFormName " and Me.cboTables with the actual names of the objects in your project.
Mar 28 '12 #7
Teresa Kline
4 New Member
Thank you so much for all your help...It Works great!!! I am new to this online forum...I have used forums to search for answers before but never to post a question so I apologize for not giving better information in my question...I didn't supply my code as I work in HR and I am prohibited to do so and I do have business reasons for the temporary tables and the need for them.....sorry. :*(

But thank you all the solution works just as I needed it to. You guys are great.

Mar 28 '12 #8
32,584 Recognized Expert Moderator MVP
That's fine Teresa. I'm not sure the code needs to be protected so rigidly (if my experience is anything to go by), but HR data certainly should. All that said, it's a learning experience for you so I'm sure you'll have a better understanding for next time :-)

Great that it all helped anyway.
Mar 28 '12 #9

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

Similar topics

by: Sham | last post by:
I have a form that is used for entering data. The problem is I have several tables, so I need some way to change the form's record source via combo box. 1. How can I make the combo box look for the tables as selections for the box, so that the user can choose the right table? I have 4 tables now, but there will be more in the future. 2. What kind of code do I need for the combo box to change record source for the form (obviously I...
by: Bob Alston | last post by:
In 2002, "GrayJay" posted the following code: I did this in a jazz record catalogue to find composers - On a form "frmComposers" Create a text box - txtFindComposer, and add the following sub Private Sub txtFindComposer_Change() Requery Me!.SetFocus
by: Bob Sanderson | last post by:
I am using a form to select a table and then opening a report using the selected table as the record source. This is a simplified description of what I'm doing. First, cboSelectBOM selects the table from a list of tables in the database. Then, command button cmdPrintXref produces the following code: Private Sub cmdPrintXref_Click() ReportSource = cboSelectBOM DoCmd.OpenReport "rptPartNoXref", acViewPreview
by: steph | last post by:
Hi, A question regarding Access 2002: I've got a form which should be displayed in Form View and in Datasheet View. But I want to use a different record source for each view. That means, when the view is switched I want to switch the record source also. I tried to put this functionality on the "On View Change" event, but
by: Robert | last post by:
I have a form that has a table; tblProjects; as its record source. The form is filtered, however, by two combo boxes in the header. One allows the user to select a client, the other a project for that client. These two selections populate the form with info from that tblProjects table. I want to create a report that would contain the information from that form but I have no idea what my record source should be for the report so that it...
by: kjworm | last post by:
Greetings all, I have a main form that does not have a record source. On that main form is a combobox that looks up values from the main table and is based off of a stored query. I also have a subform on the main form that is based on a different stored query. If a user picks an item from the dropdown, then manipulates the data via a popup form, it is then added on the popup close and will appear on the subform. I also have a button to...
by: Bob Sanderson | last post by:
I want to select a Job Number and Revision from a combo box (cboSelectBOM). I then want to open a form (frmBoM) and display the record for that Job Number and Revision When I double-click on the job in the combo box, I am running the following code: JobNum = cboSelectBOM.Column(0) Rev = cboSelectBOM.Column(1) DoCmd.OpenForm "frmBoM"
by: beacon | last post by:
Hi everybody, Using Access 2003. I'm trying to dynamically set the record source for the current form and set the control source for a text box to input data to one of three tables. I have a form (frmAddNewUser) that will add users to one of three separate tables (tblDefsAFP, tblDefsMSU, tblDefsWF) based on the selection of an option button from an option group on the same form. I have a textbox (txtNewUser) that accepts the name of...
by: CD Tom | last post by:
I found Stephen Lebans modReportToPDF and have been trying to get it to work in my application. I've downloaded his database and when I run his test it works fine. I then added it to my application and it works up to the point where it creates the snp file.then the app doesn't continue. If anybody has the modReportToPDF where it stops is at the point where he has the 'Export the selected Report to SnapShot Format. Docmd.output to...
by: Adam Tippelt | last post by:
Situation: I'm using a continuous form to display a lot of information stored in a datasheet. I'm using the form because it allows me to display multiple rows of information per 'record' which is needed as some of the records have a lot of text. However, I've needed to apply both a form of filtering system, and a way of re-ordering the form so that it is alphabetical/numerical order, depending on whiching heading is clicked. I have achieved...
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.