Hello,
Can someone tell me how to create an index for a table using DAO? I have a userform, with a combobox called "cmb_VENT_NAME". When the user chooses a value in the combobox, it runs a make-table query, but then the index that I had set up on the resulting table's field, "PROC_CODE" does not retain the index when the table is recreated through the make-table query. So then I tried to recreate the index after the make-table query runs, but it doesn't work. I don't get an error message or anything, but when I open the table, the index is not set.
I saw this link, but it looks like the solution is for ADO, not DAO.
http://www.mrexcel.com/forum/showthread.php?t=330637&highlight=create+index
Can someone tell me how to solve my problem using DAO? Below is my code. I am using Access 2000. Many thanks!
Private Sub cmb_VENT_NAME_AfterUpdate()
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim idx As DAO.Index
DoCmd.SetWarnings False
List_CODE1.RowSource = ""
List_CODE2.RowSource = ""
DoCmd.Close acTable, "tbl_SER_LIST"
DoCmd.OpenQuery "qry_SER_Choose_main"
'create index
Set db = CurrentDb
Set tdf = db.TableDefs("tbl_SER_LIST")
Set idx = tdf.CreateIndex("proc_code")
idx.Primary = True
idx.Required = True
idx.IgnoreNulls = True
Set fld = idx.CreateField("proc_code", dbText)
'update list boxes
List_CODE1.RowSource = "qry_main_code1"
List_CODE2.RowSource = "qry_main_code2"
List_CODE1.Requery
List_CODE2.Requery
DoCmd.SetWarnings True
End Sub
Can someone tell me how to create an index for a table using DAO? I have a userform, with a combobox called "cmb_VENT_NAME". When the user chooses a value in the combobox, it runs a make-table query, but then the index that I had set up on the resulting table's field, "PROC_CODE" does not retain the index when the table is recreated through the make-table query. So then I tried to recreate the index after the make-table query runs, but it doesn't work. I don't get an error message or anything, but when I open the table, the index is not set.
I saw this link, but it looks like the solution is for ADO, not DAO.
http://www.mrexcel.com/forum/showthread.php?t=330637&highlight=create+index
Can someone tell me how to solve my problem using DAO? Below is my code. I am using Access 2000. Many thanks!
Private Sub cmb_VENT_NAME_AfterUpdate()
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim idx As DAO.Index
DoCmd.SetWarnings False
List_CODE1.RowSource = ""
List_CODE2.RowSource = ""
DoCmd.Close acTable, "tbl_SER_LIST"
DoCmd.OpenQuery "qry_SER_Choose_main"
'create index
Set db = CurrentDb
Set tdf = db.TableDefs("tbl_SER_LIST")
Set idx = tdf.CreateIndex("proc_code")
idx.Primary = True
idx.Required = True
idx.IgnoreNulls = True
Set fld = idx.CreateField("proc_code", dbText)
'update list boxes
List_CODE1.RowSource = "qry_main_code1"
List_CODE2.RowSource = "qry_main_code2"
List_CODE1.Requery
List_CODE2.Requery
DoCmd.SetWarnings True
End Sub