Hi all,
Access 2K
I've written the sub below to create a temporary table when I open a form.
Although I create the table okay, I haven't figure out how to also programatically create a one to many relationship from a permanent table (tbl_Manifest) to this temp table (tmp_ManifestDetail). I want to do this because I want to automatically insert the Manifest Number from the table tbl_Manifest into each new line of data that is keyed into tmp_ManifestDetail.
To add. I will also need to delete the relationship once the temp table is dropped, this I will part I will add as part of my error handling.
Below is my code that I use to create the table and to execute the code:
Sub CreateTable(TableName)
On Error GoTo Err_CreatTable_Click
Dim DB As DAO.Database, T As DAO.TableDef, F As DAO.Field
Set DB = CurrentDb
Set T = DB.CreateTableDef(TableName)
Set F = T.CreateField("ManifestNo", dbLong)
T.Fields.Append F
Set F = T.CreateField("LineNo", dbLong)
F.Attributes = dbAutoIncrField
T.Fields.Append F
Set F = T.CreateField("ProductCode", dbLong)
T.Fields.Append F
Set F = T.CreateField("ProductName", dbText)
T.Fields.Append F
Set F = T.CreateField("Qty", dbLong)
T.Fields.Append F
Set F = T.CreateField("CreateDate", dbDate)
T.Fields.Append F
Set F = T.CreateField("ConfirmDate", dbDate)
T.Fields.Append F
DB.TableDefs.Append T
Exit_CreatTable_Click:
Exit Sub
Err_CreatTable_Click:
Select Case Err.Number
Case "3010" 'if table exists, delete it and start again
DoCmd.DeleteObject acTable, "tmp_ManifestDetail"
Form_Load
Case Else
MsgBox Err.Number & " " & Err.Description
Resume Exit_CreatTable_Click
End Select
End Sub
------------------------------------------------------------
Private Sub Form_Load()
CreateTable ("tmp_ManifestDetail") 'Run CreateTable Sub
End Sub
------------------------------------------------------------
Thanks in advance, tadynn
Access 2K
I've written the sub below to create a temporary table when I open a form.
Although I create the table okay, I haven't figure out how to also programatically create a one to many relationship from a permanent table (tbl_Manifest) to this temp table (tmp_ManifestDetail). I want to do this because I want to automatically insert the Manifest Number from the table tbl_Manifest into each new line of data that is keyed into tmp_ManifestDetail.
To add. I will also need to delete the relationship once the temp table is dropped, this I will part I will add as part of my error handling.
Below is my code that I use to create the table and to execute the code:
Sub CreateTable(TableName)
On Error GoTo Err_CreatTable_Click
Dim DB As DAO.Database, T As DAO.TableDef, F As DAO.Field
Set DB = CurrentDb
Set T = DB.CreateTableDef(TableName)
Set F = T.CreateField("ManifestNo", dbLong)
T.Fields.Append F
Set F = T.CreateField("LineNo", dbLong)
F.Attributes = dbAutoIncrField
T.Fields.Append F
Set F = T.CreateField("ProductCode", dbLong)
T.Fields.Append F
Set F = T.CreateField("ProductName", dbText)
T.Fields.Append F
Set F = T.CreateField("Qty", dbLong)
T.Fields.Append F
Set F = T.CreateField("CreateDate", dbDate)
T.Fields.Append F
Set F = T.CreateField("ConfirmDate", dbDate)
T.Fields.Append F
DB.TableDefs.Append T
Exit_CreatTable_Click:
Exit Sub
Err_CreatTable_Click:
Select Case Err.Number
Case "3010" 'if table exists, delete it and start again
DoCmd.DeleteObject acTable, "tmp_ManifestDetail"
Form_Load
Case Else
MsgBox Err.Number & " " & Err.Description
Resume Exit_CreatTable_Click
End Select
End Sub
------------------------------------------------------------
Private Sub Form_Load()
CreateTable ("tmp_ManifestDetail") 'Run CreateTable Sub
End Sub
------------------------------------------------------------
Thanks in advance, tadynn