Public Function AddVaribales(ProductRef As String)
Dim MaxRecord_New As Long
Dim rst As ADODB.Recordset
Dim strSQL As String
Dim VariableID As Long
Dim ContentLevel As Integer
Dim Status As String
Dim nUseParentSetting As Integer
Dim sValue As String
nUseParentSetting = 0
sValue = "0"
MaxRecord_New = DMax("[nID]", "[UserDefinedProperties]") + 1
Set rst = New ADODB.Recordset
'Read what variables should in actinic
strSQL = "SELECT VariablesProductShouldHave.[nVariableID], VariablesProductShouldHave.[sName], VariablesProductShouldHave.[nContentLevel], VariablesProductShouldHave.[sStatus] FROM VariablesProductShouldHave;"
rst.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockOptimistic, adCmdText
Do While Not rst.EOF
VariableID = rst("nVariableID")
ContentLevel = rst("nContentLevel")
Status = rst("sStatus")
AddRecords (ProductRef), (VariableID), (ContentLevel), (sStatus), (nUseParentSetting), (sValue)
rst.MoveNext
Loop
MsgBox "Update Complete...."
End Function
Public Function AddRecords(ProductRef As String, VariableID As Long, ContentLevel As Integer, Status As String, nUseParentSetting As Integer, sValue As String)
'Add records to table
Dim rst2 As ADODB.Recordset
Dim strSQL As String
'strSQL = "SELECT * From UserDefinedProperties WHERE nID=0"
' Check If It Exists first
strSQL = "SELECT UserDefinedProperties.*, UserDefinedProperties.[nVariableID], UserDefinedProperties.[sContentID] From UserDefinedProperties WHERE (((UserDefinedProperties.[nVariableID])=" & VariableID & ") AND ((UserDefinedProperties.[sContentID])='" & ProductRef & "'));"
Set rst2 = New ADODB.Recordset
rst2.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockOptimistic, adCmdText
If rst2.EOF = True Then
rst2.Close
Set rst2 = Nothing
strSQL = "SELECT * From UserDefinedProperties WHERE nID=0"
Set rst2 = New ADODB.Recordset
rst2.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockOptimistic, adCmdText
rst2.AddNew
rst2("nID") = MaxRecord_New
rst2("nUseParentSetting") = nUseParentSetting
rst2("sValue") = sValue
rst2("sContentID") = ProductRef
rst2("nContentLevel") = ContentLevel
rst2("sStatus") = Status
rst2("nVariableID") = VariableID
rst2.Update
MaxRecord_New = MaxRecord_New + 1
End If
rst2.Close
Set rst2 = Nothing
End Function
|