Lisa, the simplest way to do this is to open your table in Design view, and
set the Required property (lower pane) to Yes for each field.
It sounds unusual to require all fields though. If this is just because you
are having difficulties handling Nulls, this may help:
http://allenbrowne.com/casu-11.html
If you want to check for Nulls before the record is saved, you must use the
BeforeUpdate event procedure of the form.
You can loop through all controls, but some controls (such as lines and
labels) don't have a value and so cannot be tested for Null. The example
below checks if the control has a Control Source proeprty, and if so, that
it is not an unbound control (no control source used) or a calculated
control (control source starts with equals).
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim ctl As Control
Dim strMsg As String
For Each ctl In Me.Controls
If HasProperty(ctl, "ControlSource") Then
If Len(ctl.ControlSource) > 0 And _
Left(ctl.ControlSource, 1) <> "=" Then
If IsNull(ctl.Name) Then
Cancel = True
strMsg = strMsg & ctl.Name & " is Null." & vbCrLf
End If
End If
End If
Next
End Sub
Public Function HasProperty(obj As Object, strPropName As String) As Boolean
'Purpose: Return true if the object has the property.
Dim varDummy As Variant
On Error Resume Next
varDummy = obj.Properties(strPropName)
HasProperty = (Err.Number = 0)
End Function
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users -
http://allenbrowne.com/tips.html
Reply to the newsgroup. (Email address has spurious "_SpamTrap")
"Lisa B." <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Is there a code to cycle through all the controls on a form? I know there
> is, I hope.
>
> Does anyone have the code to cycle through all the controls on a form?
>
> I would like to cycle through all the controls on the from to check for
null
> values before user is allowed to move on to another record or exit the
form.
>
> I know I can do this with a lot of IF statements( an IF statement for each
> Controls name), however I would like a generic code were you don't need to
> know the name of the control.
>
> Your quick response will be greatly appreciated.
>
> Thank You
> LisaB