Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

make table queries

Status
Not open for further replies.

daz321

Programmer
May 31, 2002
17
GB
I have a make table query and would like to know if i can add a new field to act as a key (sequential numbers would do)?
 
Here's an example that you can modify to meet your needs. It creates a table and adds an autonumber key field:

Code:
Function TableMake(MyTable As String)
Dim db As Database
Dim tName As String
Dim test As String, strSQL As String
Dim td As TableDef, fld As Field
'Dim prp As Property


Set db = CurrentDb

'Trap for any errors.
On Error Resume Next
tName = MyTable

'Does table MyTable exist?  If so, delete it;
test = db.TableDefs(tName).Name

If Err <> 3265 Then
   DoCmd.DeleteObject acTable, tName
End If

'Create/recreate table

strSQL = &quot;CREATE TABLE &quot; & tName & &quot;(ObjectID counter, Type TEXT (55), &quot; _
       & &quot;FileName TEXT (55), Selected YESNO);&quot;
db.Execute strSQL

Set td = db.TableDefs(tName)

' Add autonumber field
 Set fld = td.Fields(&quot;ObjectID&quot;)
 fld.Attributes = dbAutoIncrField
 db.TableDefs.Append td
 db.TableDefs.Refresh


' Make ObjectID the key field
db.Execute &quot;CREATE INDEX NewIndex ON &quot; & tName & &quot; (ObjectID) WITH PRIMARY;&quot;

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top