mohammadagul
PrinceAtif
- Local time
- Today, 22:52
- 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
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