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

Search tables and retrieve field name

78
Ok, I hope I can explain this one well enough!

I have tables that contain similar data but are not all uniform; I use queries to create uniform data sets (same field names, formatting, etc.). I have a process that needs to update records in the original table. However, I cannot simply refer to a field name to update, as it can vary amongst the tables. My idea is to take a piece of data (in my example, an aircraft tail number, assigned to string variable tBadTailNumber), search the whole original table for it (tSource), and then get the field name of the record. I can then in turn assign the field name to a variable (tGetTailNumberField) to put in my Update code. Do any of you know how I would write this/ is this even a good idea?

I don't know much about searching, but I'd like to be able to use a wildcard for the field name, but that didn't work for me:
Expand|Select|Wrap|Line Numbers
  1. rs.FindFirst "'*' = 'N123AB'"
Jun 25 '08 #1
6 3333
kpfunf
78
I got an idea at home last night and wanted to post my solution:

Expand|Select|Wrap|Line Numbers
  1. Sub FindTNField()
  2. Dim rs As DAO.Recordset
  3. Dim db As DAO.Database
  4. Dim fld As DAO.Field
  5. Dim I As Integer
  6. Set db = CurrentDb()
  7. Set rs = db.OpenRecordset(gSource)
  8. For I = 0 To rs.Fields.Count - 1
  9. Set fld = rs.Fields(I)
  10. rs.FindFirst "[" & fld.Name & "] LIKE '" & gBadTN & "'"
  11. If Not rs.NoMatch Then
  12. gGetTNField = fld.Name
  13. Exit Sub
  14. Else
  15. End If
  16. Next
  17. End Sub
  18.  
Jun 26 '08 #2
NeoPa
32,556 Expert Mod 16PB
Nice solution (own solutions are always best in a way).
Try this though (I'm assuming gSource, gGetTNField & gBadTN are controls on your form) :
Expand|Select|Wrap|Line Numbers
  1. Private Sub FindTNField()
  2.   Dim rs As DAO.Recordset
  3.  
  4.   Set rs = CurrentDb.OpenRecordset(Me.gSource)
  5.   Me.gGetTNField = Null
  6.   On Error Resume Next
  7.   Me.gGetTNField = rs.Fields(Me.gBadTN)
  8.   Call rs.Close
  9. End Sub
Jun 27 '08 #3
NeoPa
32,556 Expert Mod 16PB
Forget last post :(

It seems I missed the point on first reading.
Jun 27 '08 #4
NeoPa
32,556 Expert Mod 16PB
As this is such an inefficient process though, would you consider adding information to the original (UNION) query that the form's based on, to indicate the field name instead (and maybe even the table name too if that would help)?
Jun 27 '08 #5
kpfunf
78
NeoPa,

My question would be how do I update the original data? I posted a while ago about trying to edit data in a Union Query (learned the sad result of "you can't").

As an example of the start of this thread, most of the tables have a field "TailNumber". However, one table may have "Tail Number", another "Tail #", and another "TNumber". In the Union they are obviously all the same ("TailNumber"). But unless I go back to the original table, isn't there no other way to edit?
Jun 27 '08 #6
NeoPa
32,556 Expert Mod 16PB
As far as I get what you're saying, your understanding is absolutely correct. You cannot update the data in the UNION query, or any form built upon that.

What I was suggesting is that in the UNION query, you have a field called [FName], for instance, that reflects the field name for each source table. This would then be available, pre-prepared, on your form.

I will try to give a bare-bones example to illustrate :
Expand|Select|Wrap|Line Numbers
  1. SELECT [TailNo], ...
  2. FROM [Table1]
  3. UNION ALL SELECT [Tail#], ...
  4. FROM [Table2]
  5. ...
...would become :
Expand|Select|Wrap|Line Numbers
  1. SELECT [TailNo], ..., 'TailNo' AS [FName]
  2. FROM [Table1]
  3. UNION ALL SELECT [Tail#], ..., 'Tail#' AS [FName]
  4. FROM [Table2]
  5. ...
Does that make more sense?
Jun 27 '08 #7

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

Similar topics

1
by: TH | last post by:
I am (still :) working on a recipe database. Now I am trying to figure out how to set it up for an ingredient search. What I want it to be able to do is three things: 1. Search based on just...
4
by: Gobi | last post by:
Hello, I have a Database with lists of Clients in each. Every year a new tables is created with the naming convention "CloseYear" ie close1999, close2000 There are tables from this year back to...
5
by: Maxi | last post by:
I have 162 tables in my database. Names of the Tables are 1, 2, ...... so on till 162. Every table has only one field (field name = Expr2) of type NUMBER (DOUBLE) with 352716 records in each table....
8
by: Steph | last post by:
Hi. I'm very new to MS Access and have been presented with an Access database of contacts by my employer. I am trying to redesign the main form of the database so that a button entitled...
0
by: Jim French | last post by:
I have a page that takes a comma delimited string and needs to bind to a Repeater control. The string is split into an Array, and each value is put into a DataBase query via a For Each loop. The...
4
by: RoadRunner | last post by:
Hi, I have a question. I am asked to produce a global search of a given corporate name, in more that one database. Each database has different table names and different field names in the tables....
5
by: rdemyan via AccessMonster.com | last post by:
I have a need to add another field to all of my tables (over 150). Not data, but an actual field. Can I code this somehow. So the code presumabley would loop through all the tables, open each...
5
by: kanley | last post by:
I have a main table with a text description field. In this field, its populated with a string of data. I need to identify from this string of data the name of the vendor using some keywords. I...
4
by: Evanescent | last post by:
Hi Guys, I am trying to create a form which allows the users to retrieve records based on the values entered or chosen in the various combo boxes and textboxes, such as the customer's name, invoice...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...
0
agi2029
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,...

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.