Re: How to detect all required fields of a form?
- From: Tom van Stiphout <no.spam.tom7744@xxxxxxx>
- Date: Mon, 19 Mar 2007 18:53:07 -0700
On Mon, 19 Mar 2007 18:26:32 -0700, Tom van Stiphout
<no.spam.tom7744@xxxxxxx> wrote:
I just realized the Autonumber portion of my question is no big deal:
blnRequiredField = rs.Fields(ctl.ControlSource).Required Or
(rs.Fields(ctl.ControlSource).Attributes And dbAutoIncrField)
Still struggling with the PK fields though.
-Tom.
I want to indicate requiredness by setting the background color of the
control. Ideally I would call a sub in Form_Load to just do its thing.
Below is what I have so far, but I realize this is of limited use
because both Autonumber fields as well as Primary Key fields not
necessarily have their Required property set, while they are required
for the purpose of the Insert action.
It seems to find out if a field is an Autonumber or PK field can be
complicated.
Does anyone have a brilliant solution?
-Tom.
Code follows:
In the Form_Load event of a form:
SetRequiredFields Me
Public Sub SetRequiredFields(frm As Form)
Dim ctl As Control
Dim rs As DAO.Recordset
Set rs = frm.RecordsetClone
For Each ctl In frm.Controls
If HasProperty(ctl, "ControlSource") Then
if rs.Fields(ctl.ControlSource).Required then
ctl.BackColor = vbRed
End If
Next ctl
Set ctl = Nothing
Set rs = Nothing
End Sub
Private Function HasProperty(ctl As Control, ByVal strPropName As
String)
Dim prop As Property
On Error Resume Next
Set prop = ctl.Properties(strPropName)
HasProperty = (Err.Number = 0)
Set prop = Nothing
End Function
.
- References:
- How to detect all required fields of a form?
- From: Tom van Stiphout
- How to detect all required fields of a form?
- Prev by Date: Re: How to detect all required fields of a form?
- Next by Date: Re: Round numbers to integer
- Previous by thread: Re: How to detect all required fields of a form?
- Next by thread: Re: How to detect all required fields of a form?
- Index(es):
Relevant Pages
|