473,402 Members | 2,053 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,402 software developers and data experts.

Dynamically find table name based on field

Just started learning VBA so I'm not sure if this is an easy problem to solve or not. I'm trying to find the name of a table based on the information in another table's field.

So I'm looking into one table called "PreferedVendor" and there is a field in it called "Vendor1" I need to look at the "Vendor1" field and check what's inside of it. If it says for example "ABC", then I need to select the table named "ABC STATUS".

Any idea how I can do that?

I have no idea where to start so I decided to ask you guys
Jun 24 '14 #1
7 1260
twinnyfo
3,653 Expert Mod 2GB
Jrod2541,

Please provide a little more information about what you will be looking for in that Table. If a field is related to another Table then obviously it exists, and you should be able to find out what is in it, but I don't think this is what you are asking.

Please provide greater detail so we can properly assist you.
Jun 24 '14 #2
Rabbit
12,516 Expert Mod 8TB
It sounds like the data model is not normalized. If you have multiple tables with the same fields where the only difference is the table name, that's usually a bad idea. It's the reason why your current query is a nightmare to build.

But that's just a guess, you haven't provided enough information for us the know for sure.
Jun 24 '14 #3
Sorry I wasn't clear enough, there is a lot detail I left out so I'm just going to start over. There are 2 tables, not directly connect, there are tables that connect them


The first table is called: "PreferedVendor".
In this table there is a field named: "Vendor1". Inside that field is a list of vendors. There is another field inside the same table named "SKU ITEM #"



Their are several other tables that are named by the vendors in the "Vendor1" field inside the table "PreferedVendor".

So if under the "Vendor1" field there are is a vendor named "ABC", I need to choose the table that is name "ABC STATUS". If inside the field "Vendor1" is a vendor named "XYZ", I need to choose the "XYZ STATUS" table. Inside these STATUS tables is a field named "VENDOR ITEM#" that match the prefered vendors.



Like I said earlier, there are tables that connect "PreferedVendor" and the "(Whatever Vendor1 is) STATUS". These tables are called "(whatever vendor 1 is) CROSS" Inside these tables are two fields called "SKU ITEM #" and "VENDOR ITEM#".

This is how "PreferedVendor" and "[Vendor1] STATUS" are connected.



Something else I should have mentioned eralier is that inside the "[Vendor1] STATUS" tables is a field named "CAN SHIP SAME DAY". I need to check to see if that table says "Yes" or "No" (This is not a boolean or a Yes/No Data Type, It is simply Short Text) for that specific "VENDOR ITEM".

If it says "Yes" Then I make a new row in a table named "orders".

If it says no then I look at the "Prefered Table" again and do this whole process over again with a field named "Vendor2", If it says "Yes" then I make a new row, if not then I move on to "Vendor3". I do this until it reaches "Vendor5"



What I can't do is make an IF statement saying "If Vendor 1 is 'ABC', then check 'ABC STATUS'" because there will be many vendors in the future so this needs to be dynamic.



I think that should cover everything. Tell me If I missed something
Jun 24 '14 #4
Rabbit
12,516 Expert Mod 8TB
As I suspected, your data model is poorly designed. You shouldn't have a table for each vendor. It makes querying the data a nightmare as you are personally experiencing right now.

You should redesign the data model to normalize the structure which would make the query much easier.

In your case, you should only have one table for vendor status and include a field that identifies the vendor. That allows you to join on Vendor1 field to the Vendor Status table.

For more information about normalizing your data, please read this article: http://bytes.com/topic/access/insigh...ble-structures
Jun 24 '14 #5
twinnyfo
3,653 Expert Mod 2GB
Jrod2541,

I think your first step is to have one table for vendors, rather than having a separate table for each vendor. If you plan on expanding the number of vendors, it would be pure insanity trying to maintain a table for each vendor. With one table, you have a list of all your vendors with all the data that is specific to each vendor in one record.

It is difficult to understand what you want to do with your tables ABC Status etc. Are these just one record? If not, what types of data do you have in these tables?

Without knowing how your tables are set up, it's impossible to say how to set them up better. Right now, the multiple tables option does not seem to fit the basic principles of database normalization (see this topic).

Either way, it looks like you will need some re-engineering, but we can work through those steps to get you up and running.
Jun 24 '14 #6
Alright, Thanks guys. I'll be more careful when organizing my tables. I'll keep that article for the future. As for now, I'm just going to focus on redesigning my database.

Thanks again
Jun 24 '14 #7
NeoPa
32,556 Expert Mod 16PB
I fully support what the other guys have said about database normalisation. It may seem a pain to restart from scratch now, but believe me that is nothing to the pain you would have experienced had you proceeded along your original course.

It's probably hard to be hit with something like this and feel really lucky but, trust me, you have been.

As a final tip - Note the spelling of "Preferred". It may seem unimportant but if your work is for someone else (contracting for instance) then misspelling common words is a sure-fire way to lose respect/work.

Good luck with your project and remember we can continue to help.

Last, but not least, if you're new to Access work then you'll find a bunch of helpful tutorials if you follow the link found in Database Analyser.
Jun 24 '14 #8

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

Similar topics

2
by: Daniel | last post by:
I use an Access database to basically take data exports, import them, manipulate the data, and then turn them into exportable reports. I do this using numerous macros, and queries to get the data...
1
by: Shimon Sofer | last post by:
Hello Does anybody know how to change table name (and field name) using SQL query ? I want to use it from Delphi/ADO. Thanks
0
by: b_madhubharathi | last post by:
hi frnz, In my coding i take the tablename and columns from the system and i execute the new query with that values. if i give the table name directly it is working.but if i give the table in...
2
by: nel | last post by:
anybody of u can help me? i want some code to insert array coding in database mysql..where this process to many table and to specified field... this table name and field name i taken from database...
5
by: devx777 | last post by:
Hello, I am trying to find some information or an example on how to build a dynamic query in DB2 that would allow me to join a table which its name is stored as a field value on another table....
6
by: Inge Jones | last post by:
I have a form that dynamically generates Submit buttons. I want all the buttons to display the same text "More info" while their names are dynamically generated numeric names (they point to database...
4
blyxx86
by: blyxx86 | last post by:
Hi everyone, I am using some VB code to have a "Notes" table be stored for use on all forms that relates to the specific record in any other table. (I haven't used the terminology in a while, but...
1
by: jgentes | last post by:
I am in the process of normalizing and re-creating a database that was a total maintanence mess. Currently the database has 640 tables. each table is an assembly and contains the data of its sub...
2
by: SNFBS | last post by:
how to get the table name based on column name? I got column name but i dont know the location of that column, in which table.since i got about >300 tables in database
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
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...

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.