Required Field in a Table

mohammadagul

PrinceAtif
Local time
Tomorrow, 03:34
Joined
Mar 14, 2004
Messages
298
I have a field called description In a table. It is set as required, when a user leave this field blanc in a form, a message stating that is field cannot be null.

What I did was that I placed “Validate” in the tag progerty of the control(s) . Crate a txtbox named backcolor (and set its default value to 16777214[white]) and insert the following into the save button event procedure.

Private Sub cmdSave_Click()
Dim currctl As Integer, numctls As Integer

Dim ctl As Control
numctls = Screen.ActiveForm.Count



For currctl = 0 To numctls - 1
Set ctl = Me(currctl)
If ctl.Tag = "Validate" Then
If IsNull(ctl) Then
MsgBox "Please Enter", vbOKOnly, "Enter"
ctl.BackColor = 255
ctl.SetFocus
Exit For
Else
If Not IsNull(ctl) Then
ctl.BackColor = Me!BackColor.BackColor
End If
End If

Next currctl
End If

End Sub

Docmd.doMenuItem acFormBar, acRecordsMenu, acSaveRecord,,acManuVer70

What I was thinking that this will look at all controls and trun an empty control/field red if it is not filled in and abordt save until it is, but unfortunately it is giving a compiliation error. Evertime the comes as follows

Next without For

Where as there is For and there Exit For and There is also next statement. What am I doing wrong here.
Please Help
 
m,

Code:
Private Sub cmdSave_Click()
Dim currctl As Integer, numctls As Integer

Dim ctl As Control
numctls = Screen.ActiveForm.Count

For currctl = 0 To numctls - 1
   Set ctl = Me(currctl)
   If ctl.Tag = "Validate" Then
      If IsNull(ctl) Then
         MsgBox "Please Enter", vbOKOnly, "Enter"
         ctl.BackColor = 255
         ctl.SetFocus
         Exit For
      Else
         If Not IsNull(ctl) Then
            ctl.BackColor = Me!BackColor.BackColor
         End If
      End If

Next currctl <-- Swap this line and the next one
End If

End Sub

Wayne
 
Tried your Suggestion but same thing. it is giving the same error
 

Users who are viewing this thread

Back
Top Bottom