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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create a table with an index

Status
Not open for further replies.

WebStar

Programmer
May 1, 2002
69
DE
Hi,
I have a function that has to delete some fields in an access database. The problem is that the table is created dinamically from code. If I set the "MainWPID" field to be Indexed(Duplicated OK) from MS Acces everything works ok. But I don't know how to create an indexed field from program.
anybody has an ideea?

The table has these fields:
"MainWPID" - string
"ID" - string
"Value" - string
I want the "MainWPID" field to be indexed.
Thank you!

this is the delete function:
Code:
Public Function DeleteData(dbPath As String, UserID As String) As Boolean
    Dim rs As Recordset
    Dim db As Database, strTemp As String
    
    On Error GoTo ErrorHandler
    
    Set db = OpenDatabase(dbPath)
    'exist in database?
    Set rs = db.OpenRecordset(UserID, dbOpenTable)
    strTemp = Main.BASEN(36)
    With rs
        .index = "MainWPID"
        .Seek "=", strTemp
        Do While Not .NoMatch
            .Delete
            .Seek "=", Main.BASEN(36)
        Loop
    End With
    GoTo TheEnd
ErrorHandler:
    GoTo TheEnd
TheEnd:
    db.Close
End Function
 
Hi WebStar,

The easiest way is a bit of DDL:

Code:
Docmd.runsql "CREATE INDEX MainWPID ON" & UserID & "(MainWPID)"

where UserID (as per your code) is a string containing the Table name.

Enjoy,
Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top