jordanking
Programmer
- Sep 8, 2005
- 351
hello,
I was wondering if there is a way to determine if a recordset's field allows nulls based on the desing of the underlying table(s).
I am using unbound forms to control the user data. All of the columns in the table have equivelent controls on the form.
I want to have a modular piece of code that checks all the fields on any form (each control's name matches the recordset's field name) to see if the fields that can not be null have values.
i have removed sections of this code to make it more condensed
thanks in advance
I was wondering if there is a way to determine if a recordset's field allows nulls based on the desing of the underlying table(s).
I am using unbound forms to control the user data. All of the columns in the table have equivelent controls on the form.
I want to have a modular piece of code that checks all the fields on any form (each control's name matches the recordset's field name) to see if the fields that can not be null have values.
Code:
Dim rst As New ADODB.Recordset
Dim fld As ADODB.Field
Dim ctl As Control
Dim vartemp As Variant
Dim sqlSelect As String
'Open connection
cnn.Open frm.Controls("xProvider") & frm.Controls("xDataSource")
'Open recordset
sqlSelect = "Select * From " & frm.Controls("xRecordset")
rst.Open sqlSelect, cnn, adOpenStatic
'Iterate through controls on form that match fields in recordset
For Each ctl In frm
'if error the field is not on the form
vartemp = rst.Fields(ctl.Name).Name
On Error Resume Next
Err = 0
If ctl.Enabled Then
if rst.Fields(ctl.Name)."allownulls" = false and rst.Fields(ctl.Name).value = null then
'alert user
end if
End If
End If
Next
i have removed sections of this code to make it more condensed
thanks in advance