sqldevrequiretektips
Programmer
Following function create a table on MS Access
Name WLMod_Denormalized...
every thing works fine but now i want to change one property:
How do i set all column names property called required = NO
In short in this table required data entry = NO
by default it creates a field with require data entry.
how do i change it??
please help me out...
Public Function WLMod_DenormalizedTable_Create() As Boolean
Dim wk_Catalog As ADOX.Catalog
Dim LocalDb As clsLocalDb
Dim Conn1 As ADODB.Connection
Dim wk_Table As ADOX.Table
Dim sql1 As String
Dim Rset1 As ADODB.Recordset
Dim sql2 As String
Dim Rset2 As ADODB.Recordset
Dim Wk_WlDayId As String
Dim wk_WlActCatId As String
Dim wk_WlEmpTypeId As String
Dim ColsAdded As Integer
WLMod_DenormalizedTable_Create = False
Dim ErrMsg As String
Err.Clear
On Error GoTo quit
ColsAdded = 0
Set wk_Catalog = New ADOX.Catalog
Set LocalDb = New clsLocalDb
Set Conn1 = New ADODB.Connection
Conn1.Open LocalDb.ConnectionString
wk_Catalog.ActiveConnection = Conn1
Set wk_Table = New ADOX.Table
wk_Table.Name = "WLMod_Denormalized"
wk_Table.ParentCatalog = wk_Catalog
' delete the table, if it exists
On Error Resume Next
wk_Catalog.Tables.Delete wk_Table.Name
Err.Clear
On Error GoTo quit
wk_Catalog.Tables.Append wk_Table
wk_Table.Columns.Append "CustLifeNo", adInteger
wk_Table.Columns.Append "WeekNo", adInteger
' get days
Dim newConn As ADODB.Connection
Set newConn = New ADODB.Connection
newConn.Open LocalDb.ConnectionString
Set Rset1 = New ADODB.Recordset
Rset1.ActiveConnection = newConn
sql1 = "select * from tblWLDay order by SortOrd"
Rset1.Open sql1, Conn1, adOpenForwardOnly, adLockReadOnly, adCmdText
If Rset1.EOF Or Rset1.BOF Then
ErrMsg = "Unable To Find Any Useable Days In Mod Template"
GoTo quit
End If
Rset1.MoveFirst
'loop thru days
Do While Not Rset1.EOF
Wk_WlDayId = Rset1.Fields.Item(0).value ' shortcut
' add this day's units col
wk_Table.Columns.Append Wk_WlDayId & "_" & "Units", adInteger
' get valid ActCatID from tblWIActCat
Set Rset2 = New ADODB.Recordset
sql2 = "Select WLActCatId from tblWLActCatId Order by SortOrd"
Rset2.Open sql2, Conn1, adOpenStatic, adLockReadOnly, adCmdText
If Not Rset2.EOF And Not Rset2.BOF Then
Rset2.MoveFirst
Do While Not Rset2.EOF
wk_WlActCatId = Rset2.Fields.Item(0).value ' Pick up first Item ...
wk_Table.Columns.Append Wk_WlDayId & "_Act_" & wk_WlActCatId, adVarWChar, 3 ' refers to WlModTpl_Value in WlModTplAct
Format$
ColsAdded = ColsAdded + 1
Rset2.MoveNext
Loop
End If
Set Rset2 = DbObjCloseAndSetToNothing(Rset2)
' get valid emp types from tblWIEmpType
Set Rset2 = New ADODB.Recordset
sql2 = "select WLEmpTypeId from tblWLEmpType Order By SortOrd"
Rset2.Open sql2, Conn1, adOpenStatic, adLockReadOnly, adCmdText
If Not Rset2.EOF And Not Rset2.BOF Then
Rset2.MoveFirst
Do While Not Rset2.EOF
wk_WlEmpTypeId = Rset2.Fields.Item(0).value
wk_Table.Columns.Append Wk_WlDayId & "_Emp_" & wk_WlEmpTypeId, adBoolean ' refers to WlModTpl_Value in WlModTplEmp
ColsAdded = ColsAdded + 1
Rset2.MoveNext
Loop
End If
Set Rset2 = DbObjCloseAndSetToNothing(Rset2)
Rset1.MoveNext ' move on to next day
Loop
' define primary key
wk_Table.Keys.Append "pk", adKeyPrimary, "CustLifeNo"
If ColsAdded = 0 Then
ErrMsg = "Unable To Find Any Useable Columns While Denormalizing WlModTplAct & WlModTplEmp"
GoTo quit
End If
WLMod_DenormalizedTable_Create = True
quit:
If Err.Number <> 0 And ErrMsg = "" Then ErrMsg = IIf(Err.Description <> "", Err.Description, CStr(Err.Number))
'MsgBox Err.Description
'Debug.Print Err.Description
Set Rset1 = DbObjCloseAndSetToNothing(Rset1)
Set Rset2 = DbObjCloseAndSetToNothing(Rset2)
Set Conn1 = DbObjCloseAndSetToNothing(Conn1)
If Not LocalDb Is Nothing Then Set LocalDb = Nothing
If ErrMsg <> "" Then On Error GoTo 0: Err.Raise vbObjectError + 513, m_Name, ErrMsg
End Function
Name WLMod_Denormalized...
every thing works fine but now i want to change one property:
How do i set all column names property called required = NO
In short in this table required data entry = NO
by default it creates a field with require data entry.
how do i change it??
please help me out...
Public Function WLMod_DenormalizedTable_Create() As Boolean
Dim wk_Catalog As ADOX.Catalog
Dim LocalDb As clsLocalDb
Dim Conn1 As ADODB.Connection
Dim wk_Table As ADOX.Table
Dim sql1 As String
Dim Rset1 As ADODB.Recordset
Dim sql2 As String
Dim Rset2 As ADODB.Recordset
Dim Wk_WlDayId As String
Dim wk_WlActCatId As String
Dim wk_WlEmpTypeId As String
Dim ColsAdded As Integer
WLMod_DenormalizedTable_Create = False
Dim ErrMsg As String
Err.Clear
On Error GoTo quit
ColsAdded = 0
Set wk_Catalog = New ADOX.Catalog
Set LocalDb = New clsLocalDb
Set Conn1 = New ADODB.Connection
Conn1.Open LocalDb.ConnectionString
wk_Catalog.ActiveConnection = Conn1
Set wk_Table = New ADOX.Table
wk_Table.Name = "WLMod_Denormalized"
wk_Table.ParentCatalog = wk_Catalog
' delete the table, if it exists
On Error Resume Next
wk_Catalog.Tables.Delete wk_Table.Name
Err.Clear
On Error GoTo quit
wk_Catalog.Tables.Append wk_Table
wk_Table.Columns.Append "CustLifeNo", adInteger
wk_Table.Columns.Append "WeekNo", adInteger
' get days
Dim newConn As ADODB.Connection
Set newConn = New ADODB.Connection
newConn.Open LocalDb.ConnectionString
Set Rset1 = New ADODB.Recordset
Rset1.ActiveConnection = newConn
sql1 = "select * from tblWLDay order by SortOrd"
Rset1.Open sql1, Conn1, adOpenForwardOnly, adLockReadOnly, adCmdText
If Rset1.EOF Or Rset1.BOF Then
ErrMsg = "Unable To Find Any Useable Days In Mod Template"
GoTo quit
End If
Rset1.MoveFirst
'loop thru days
Do While Not Rset1.EOF
Wk_WlDayId = Rset1.Fields.Item(0).value ' shortcut
' add this day's units col
wk_Table.Columns.Append Wk_WlDayId & "_" & "Units", adInteger
' get valid ActCatID from tblWIActCat
Set Rset2 = New ADODB.Recordset
sql2 = "Select WLActCatId from tblWLActCatId Order by SortOrd"
Rset2.Open sql2, Conn1, adOpenStatic, adLockReadOnly, adCmdText
If Not Rset2.EOF And Not Rset2.BOF Then
Rset2.MoveFirst
Do While Not Rset2.EOF
wk_WlActCatId = Rset2.Fields.Item(0).value ' Pick up first Item ...
wk_Table.Columns.Append Wk_WlDayId & "_Act_" & wk_WlActCatId, adVarWChar, 3 ' refers to WlModTpl_Value in WlModTplAct
Format$
ColsAdded = ColsAdded + 1
Rset2.MoveNext
Loop
End If
Set Rset2 = DbObjCloseAndSetToNothing(Rset2)
' get valid emp types from tblWIEmpType
Set Rset2 = New ADODB.Recordset
sql2 = "select WLEmpTypeId from tblWLEmpType Order By SortOrd"
Rset2.Open sql2, Conn1, adOpenStatic, adLockReadOnly, adCmdText
If Not Rset2.EOF And Not Rset2.BOF Then
Rset2.MoveFirst
Do While Not Rset2.EOF
wk_WlEmpTypeId = Rset2.Fields.Item(0).value
wk_Table.Columns.Append Wk_WlDayId & "_Emp_" & wk_WlEmpTypeId, adBoolean ' refers to WlModTpl_Value in WlModTplEmp
ColsAdded = ColsAdded + 1
Rset2.MoveNext
Loop
End If
Set Rset2 = DbObjCloseAndSetToNothing(Rset2)
Rset1.MoveNext ' move on to next day
Loop
' define primary key
wk_Table.Keys.Append "pk", adKeyPrimary, "CustLifeNo"
If ColsAdded = 0 Then
ErrMsg = "Unable To Find Any Useable Columns While Denormalizing WlModTplAct & WlModTplEmp"
GoTo quit
End If
WLMod_DenormalizedTable_Create = True
quit:
If Err.Number <> 0 And ErrMsg = "" Then ErrMsg = IIf(Err.Description <> "", Err.Description, CStr(Err.Number))
'MsgBox Err.Description
'Debug.Print Err.Description
Set Rset1 = DbObjCloseAndSetToNothing(Rset1)
Set Rset2 = DbObjCloseAndSetToNothing(Rset2)
Set Conn1 = DbObjCloseAndSetToNothing(Conn1)
If Not LocalDb Is Nothing Then Set LocalDb = Nothing
If ErrMsg <> "" Then On Error GoTo 0: Err.Raise vbObjectError + 513, m_Name, ErrMsg
End Function