T
Terry Holland
I am programmatically creating and populating a table (using code supplied).
When I check my database (access) and look in the newly created table I dont
see any data. If I create the query
Select * From tblStockGroupDiscount I get no data returned.
If however I create a query
SELECT tblStockGroupDiscount.sgdi_txt_StockGroupID,
tblStockGroupDiscount.sgdi_sgl_Discount
FROM [Stock Groups] INNER JOIN tblStockGroupDiscount ON [Stock
Groups].StockGroupId = tblStockGroupDiscount.sgdi_txt_StockGroupID;
The data in the table is displayed.
I do not have any filters on the table & I have not selected DataEntry.
Any ideas?
Terry Holland
================================================
Code
================================================
Private Function ApplyUpdate_83()
ApplyUpdate 83, "2.0_29"
Update_AddTableStockGroupDiscount
Update_PopulateStockGroupDiscountTable
Update_AddQueryApplyDiscountRates
End Function
================================================
Private Function Update_AddTableStockGroupDiscount()
Dim tdf As dao.TableDef
Dim idx As dao.Index
If dbBIDS Is Nothing Then modDataBase.OpenBIDSDatabase
'Check if table exists and exit function if it does
For Each tdf In dbBIDS.TableDefs
If tdf.Name = "tblStockGroupDiscount" Then
'dbBIDS.TableDefs.Delete (tdf.Name)
Exit Function
End If
Next
With dbBIDS
Set tdf = .CreateTableDef("tblStockGroupDiscount")
'Add fields to table
Call AddDAOField(tdf, "sgdi_lng_id", dbLong, , dbAutoIncrField)
Call AddDAOField(tdf, "sgdi_txt_StockGroupID", dbText, 6)
Call AddDAOField(tdf, "sgdi_sgl_Discount", dbSingle)
'create primary key
Set idx = tdf.CreateIndex("idxPKStockGroupDiscount")
With idx
.Primary = True
.Fields = "sgdi_lng_id"
End With
tdf.Indexes.Append idx
.TableDefs.Append tdf
End With
'Cant add a relationship as the StockGroups table is a link from another
DB
'Call AddDAORelationship(dbBIDS, "Stock Groups",
"tblStockGroupDiscount", "StockGroupId", "sgdi_txt_StockGroupID",
dbRelationUpdateCascade + dbRelationDeleteCascade)
End Function
================================================
Private Function AddDAOField(tdf As dao.TableDef, StrName As String, dbType
As dao.DataTypeEnum, Optional intLength As Integer = -1, Optional
intAttributes As Integer = -1) As dao.Field
Dim fld As dao.Field
Set fld = New dao.Field
With fld
.Name = StrName
.Type = dbType
If intLength > 0 Then .Size = intLength
If intAttributes > 0 Then .Attributes = intAttributes
End With
tdf.Fields.Append fld
Set fld = Nothing
End Function
Private Function Update_PopulateStockGroupDiscountTable()
'Populates tblStockGroupDiscount with data in text file
MaterialDiscountRate.txt
Dim objTextFile As New clsTextFile
Dim cmm As ADODB.Command
'Dim strFields As Variant
Dim strValues() As String
Dim rst As New ADODB.Recordset
rst.Open "select * from tblStockGroupDiscount", ADOConnection,
adOpenKeyset, adLockOptimistic
With objTextFile
.OpenFile "MaterialDiscountRate.txt"
'MsgBox "Opened file"
While Not .EndOfFile
strValues = Split(.ReadFromFile, ",")
'MsgBox "Found " & strValues(0) & " in file"
rst.Filter = "sgdi_txt_StockGroupID='" & strValues(0) & "'"
If rst.EOF Then
'MsgBox "Adding " & strValues(0) & " in file"
rst.AddNew 'strFields, strValues
Else
'MsgBox "Updating " & strValues(0) & " in file"
End If
rst.Fields("sgdi_txt_StockGroupID") = strValues(0)
rst.Fields("sgdi_sgl_Discount") = strValues(1)
rst.Update
Wend
.CloseFile
rst.Close
End With
End Function
When I check my database (access) and look in the newly created table I dont
see any data. If I create the query
Select * From tblStockGroupDiscount I get no data returned.
If however I create a query
SELECT tblStockGroupDiscount.sgdi_txt_StockGroupID,
tblStockGroupDiscount.sgdi_sgl_Discount
FROM [Stock Groups] INNER JOIN tblStockGroupDiscount ON [Stock
Groups].StockGroupId = tblStockGroupDiscount.sgdi_txt_StockGroupID;
The data in the table is displayed.
I do not have any filters on the table & I have not selected DataEntry.
Any ideas?
Terry Holland
================================================
Code
================================================
Private Function ApplyUpdate_83()
ApplyUpdate 83, "2.0_29"
Update_AddTableStockGroupDiscount
Update_PopulateStockGroupDiscountTable
Update_AddQueryApplyDiscountRates
End Function
================================================
Private Function Update_AddTableStockGroupDiscount()
Dim tdf As dao.TableDef
Dim idx As dao.Index
If dbBIDS Is Nothing Then modDataBase.OpenBIDSDatabase
'Check if table exists and exit function if it does
For Each tdf In dbBIDS.TableDefs
If tdf.Name = "tblStockGroupDiscount" Then
'dbBIDS.TableDefs.Delete (tdf.Name)
Exit Function
End If
Next
With dbBIDS
Set tdf = .CreateTableDef("tblStockGroupDiscount")
'Add fields to table
Call AddDAOField(tdf, "sgdi_lng_id", dbLong, , dbAutoIncrField)
Call AddDAOField(tdf, "sgdi_txt_StockGroupID", dbText, 6)
Call AddDAOField(tdf, "sgdi_sgl_Discount", dbSingle)
'create primary key
Set idx = tdf.CreateIndex("idxPKStockGroupDiscount")
With idx
.Primary = True
.Fields = "sgdi_lng_id"
End With
tdf.Indexes.Append idx
.TableDefs.Append tdf
End With
'Cant add a relationship as the StockGroups table is a link from another
DB
'Call AddDAORelationship(dbBIDS, "Stock Groups",
"tblStockGroupDiscount", "StockGroupId", "sgdi_txt_StockGroupID",
dbRelationUpdateCascade + dbRelationDeleteCascade)
End Function
================================================
Private Function AddDAOField(tdf As dao.TableDef, StrName As String, dbType
As dao.DataTypeEnum, Optional intLength As Integer = -1, Optional
intAttributes As Integer = -1) As dao.Field
Dim fld As dao.Field
Set fld = New dao.Field
With fld
.Name = StrName
.Type = dbType
If intLength > 0 Then .Size = intLength
If intAttributes > 0 Then .Attributes = intAttributes
End With
tdf.Fields.Append fld
Set fld = Nothing
End Function
Private Function Update_PopulateStockGroupDiscountTable()
'Populates tblStockGroupDiscount with data in text file
MaterialDiscountRate.txt
Dim objTextFile As New clsTextFile
Dim cmm As ADODB.Command
'Dim strFields As Variant
Dim strValues() As String
Dim rst As New ADODB.Recordset
rst.Open "select * from tblStockGroupDiscount", ADOConnection,
adOpenKeyset, adLockOptimistic
With objTextFile
.OpenFile "MaterialDiscountRate.txt"
'MsgBox "Opened file"
While Not .EndOfFile
strValues = Split(.ReadFromFile, ",")
'MsgBox "Found " & strValues(0) & " in file"
rst.Filter = "sgdi_txt_StockGroupID='" & strValues(0) & "'"
If rst.EOF Then
'MsgBox "Adding " & strValues(0) & " in file"
rst.AddNew 'strFields, strValues
Else
'MsgBox "Updating " & strValues(0) & " in file"
End If
rst.Fields("sgdi_txt_StockGroupID") = strValues(0)
rst.Fields("sgdi_sgl_Discount") = strValues(1)
rst.Update
Wend
.CloseFile
rst.Close
End With
End Function