I'm writing this program that works with databases. In the program, you work with two different types of tables, both of which are created in this one database. So anyway, if a user goes to create a new table in, lets say format 1, here is the code i use:
Dim db as Database
Dim td as TableDef, TempTd as TableDef
Dim fields(5) As Field
Dim dbrecordset As Recordset
Tablename = InputBox("Enter title of table:", "New Table"
Set db = DBEngine.Workspaces(0).Opendatabase("c:\program files\olds\data\OLDS Database.mdb"
Set td = db.CreateTableDef(TableName)
Set fields(0) = td.CreateField("Category", dbText)
Set fields(1) = td.CreateField("Year", dbText)
Set fields(2) = td.CreateField("Title", dbText)
Set fields(3) = td.CreateField("BinderNum", dbText)
Set fields(4) = td.CreateField("FormNum", dbText)
Set fields(5) = td.CreateField("Comments", dbText)
td.fields.Append fields(0)
td.fields.Append fields(1)
td.fields.Append fields(2)
td.fields.Append fields(3)
td.fields.Append fields(4)
td.fields.Append fields(5)
db.TableDefs.Append td
Set dbrecordset = db.OpenRecordset(Tablename, dbOpenTable)
So that is the code when the user creates a new table.
When the user saves the table, the program creates a textfile named after data1.recordsource, and contains a single line of text containing data1.recordsource:
Open "c:\Program Files\OLDS\data\savedata\" + Data1.RecordSource + ".txt" For Output As #1
Print #1, Data1.Recordsource
Close #1
That works too. However, when i try to load a table, there is a form with a button and a Filelistbox which lists all the files in the savadata directory. When the button is clicked:
Dim opentablename
Open "C:\program files\olds\data\savedata\" + File1.Filename For Input As #1
Input #1, opentablename
Close #1
Index.Data1.RecordSource = opentablename
Unload Me
Index.show
However, when I do that, and i try to navigate around the opened table in the Index form, it doesn't recognize that i told it to open the tablename. Can someone please either help me fix my code, or tell me a better way to save/open tables. Thanks
-Mike
Dim db as Database
Dim td as TableDef, TempTd as TableDef
Dim fields(5) As Field
Dim dbrecordset As Recordset
Tablename = InputBox("Enter title of table:", "New Table"
Set db = DBEngine.Workspaces(0).Opendatabase("c:\program files\olds\data\OLDS Database.mdb"
Set td = db.CreateTableDef(TableName)
Set fields(0) = td.CreateField("Category", dbText)
Set fields(1) = td.CreateField("Year", dbText)
Set fields(2) = td.CreateField("Title", dbText)
Set fields(3) = td.CreateField("BinderNum", dbText)
Set fields(4) = td.CreateField("FormNum", dbText)
Set fields(5) = td.CreateField("Comments", dbText)
td.fields.Append fields(0)
td.fields.Append fields(1)
td.fields.Append fields(2)
td.fields.Append fields(3)
td.fields.Append fields(4)
td.fields.Append fields(5)
db.TableDefs.Append td
Set dbrecordset = db.OpenRecordset(Tablename, dbOpenTable)
So that is the code when the user creates a new table.
When the user saves the table, the program creates a textfile named after data1.recordsource, and contains a single line of text containing data1.recordsource:
Open "c:\Program Files\OLDS\data\savedata\" + Data1.RecordSource + ".txt" For Output As #1
Print #1, Data1.Recordsource
Close #1
That works too. However, when i try to load a table, there is a form with a button and a Filelistbox which lists all the files in the savadata directory. When the button is clicked:
Dim opentablename
Open "C:\program files\olds\data\savedata\" + File1.Filename For Input As #1
Input #1, opentablename
Close #1
Index.Data1.RecordSource = opentablename
Unload Me
Index.show
However, when I do that, and i try to navigate around the opened table in the Index form, it doesn't recognize that i told it to open the tablename. Can someone please either help me fix my code, or tell me a better way to save/open tables. Thanks
-Mike