View Full Version : Check for entry - Any comments?


reclusivemonkey
12-01-2005, 09:56 AM
Just going through a DB today and I was struck by an idea... I was writing code to check fields for data, and if they were empty I was prompting the user. Now I usually try to fill in the status bar text and control tip text with some like "Please select a month" or whatever. So, I came up with this;


Public Function CheckForEntry(ByRef myControl As Variant)

' Why write a check for an entry in each control when we can function it?
If IsNull(myControl) Then
If IsNull(myControl.ControlTipText) Then
MsgBox "Please check you have completed all the necessary fields."
DoCmd.GoToControl myControl.Name
Else
MsgBox myControl.ControlTipText
DoCmd.GoToControl myControl.Name
End
End If
Else
End If

End Function


Now of course if you don't populate the ControlTipText or the StatusBarText then its not much good, but I was quite pleased with myself. I am sure someone can write this to use an array and make it generally more useful...

ozinm
12-12-2005, 04:17 AM
Cool.
you could also use the same sort of thing to do a check and report before saving the record.
All you'd need to do is something like setting the Tag for each control that has to be filled in to TRUE.
You could then get the code to loop through all the items in Me.Form.Controls checking the Tag and Value of the control.