473,418 Members | 1,834 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,418 software developers and data experts.

Find Primary Key field



Thanks for taking the time to read my question.

I have code that I am using to tell me info about fields in a table. It
is in a loop so I can move through all the fields in the table.

db.TableDefs(x).Fields(i)

Is it possible to tell which field is the primary key? If yes, then
how? I can't find anything to add to db.TableDefs(x).Fields(i).???? to
get Primary Key info.

I'd like to be able to have the code in this loop.

Here is my loop right now:
---------------------------------------------------
Dim x As Integer, db As Database, rst As Recordset
Dim NumOfRecs As Integer
Set db = CurrentDb
Set rst = db.OpenRecordset("tblTableDetails")

On Error GoTo ViewProperties_Err

x = 0
Do Until x = DLookup("CountOfName", "qryNumberOfTables") + 7
If db.TableDefs(x).Name = Me.lst_TableNames Then
For i = 0 To db.TableDefs(x).Fields.Count - 1
With rst
.AddNew
!FieldName = db.TableDefs(x).Fields(i).Name
If db.TableDefs(x).Fields(i).Type = 10 Then
!FieldType = "Text"
!FieldSize = db.TableDefs(x).Fields(i).Size
Else
If db.TableDefs(x).Fields(i).Type = 4 Then
!FieldType = "Integer"
ElseIf db.TableDefs(x).Fields(i).Type = 7 Then
!FieldType = "Double"
ElseIf db.TableDefs(x).Fields(i).Type = 8 Then
!FieldType = "Date"
End If
End If
.Update
End With
Next
NumberOfRecs = db.TableDefs(x).RecordCount
Exit Do
End If
x = x + 1
Loop
---------------------------------------------------

Thanks so very much for your help.

Brad

*** Sent via Developersdex http://www.developersdex.com ***
Dec 9 '05 #1
2 8647
rkc
Brad wrote:
Thanks for taking the time to read my question.

I have code that I am using to tell me info about fields in a table. It
is in a loop so I can move through all the fields in the table.

db.TableDefs(x).Fields(i)

Is it possible to tell which field is the primary key? If yes, then
how? I can't find anything to add to db.TableDefs(x).Fields(i).???? to
get Primary Key info.


<snip>

Using DAO you can look through the TableDef.Indexes collection. There is
an Index.Primary property that is true if the index is a primary key
index. You can then find the field names by looking at the fields
collection of the Index. There may be a more direct way using DAO that I
am not aware of.
Dec 9 '05 #2

Perfect!!

Thanks so much,

Brad
*** Sent via Developersdex http://www.developersdex.com ***
Dec 9 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Graham Mattingley | last post by:
If I insert a value into a table what is the best way to find the Primary Field Value.. +--------------+---------------------+------+-----+ | Field | Type | Null | Key |...
4
by: Mavis Tilden | last post by:
Hi all, So I've been reading the newsgroups, and reading a few books trying to learn SQL and SQL Server 2000. The books tell me I need a Primary Key, and that every table should have one. I know...
2
by: Scott Adams | last post by:
When calling the Find function of a DataRowCollection, one has two options: Overloads Public Function Find(ByVal key As Object) As DataRow or Overloads Public Function Find(ByVal keys() As...
4
by: Filips Benoit | last post by:
Dear All, Is ( how) it possible to find the tablename of the table that is related to a field. Field CLIENT_TITLE_ID is related to table TITLE Thanks, Filip
18
by: Thomas A. Anderson | last post by:
I am a bit confused in creating a composite primary key. I have three table with two of the tables containing primary keys. I have two of the tables (each with a primary key) having one to many...
4
by: Marc Pelletier | last post by:
Hello, I am trying to use the find method to locate a particular record in a table. The code is : objectfindTheseVals = new object; findTheseVals = station_ID; // an integer findTheseVals =...
33
by: Kevin Brammer | last post by:
I'm trying to use seek to check for the existence of a record before saving, so there are no duplicate entries (is there another way?). I have a "groups" table, which has GroupID Island...
8
by: Paul Hunter | last post by:
I am new to databases and thus to Access. I have a situation where I am trying to figure out how to key some tables I am working with. Consider that I have a database of my own records which are...
115
by: LurfysMa | last post by:
Most of the reference books recommend autonum primary keys, but the Access help says that any unique keys will work. What are the tradeoffs? I have several tables that have unique fields. Can...
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
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
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
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
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,...
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...
0
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...

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.