C
Christine
I have the following code in all of my forms to check for
blank fields before carrying out an action. (Found it
someplace either here or on the web, can't recall.)In each
form, an action takes place if Cancel = False.
I realise that repeating this code in all of the project's
forms isn't very tidy. Does it belong in a module, a
function? How do you call a module and what code has to be
before and after it? Does "Cancel" have to be declared as
public in each form?
Dim ctl As Control
Dim intMsgResponse As Integer
' Loop through all the controls on the form
For Each ctl In Me.Controls
' Check the tag property
If ctl.Tag = "RequiredField" Then
' Check this control has a value
If ctl = "" Or IsNull(ctl) Then
' No Value - Cancel the update event
Cancel = True
End If
End If
Next
' Check to see if a required field was blank and
inform the user
If Cancel = True Then
MsgBox "Please fill in all required fields.",
vbExclamation, "Information is missing"
End If
Many thanks,
Christine
blank fields before carrying out an action. (Found it
someplace either here or on the web, can't recall.)In each
form, an action takes place if Cancel = False.
I realise that repeating this code in all of the project's
forms isn't very tidy. Does it belong in a module, a
function? How do you call a module and what code has to be
before and after it? Does "Cancel" have to be declared as
public in each form?
Dim ctl As Control
Dim intMsgResponse As Integer
' Loop through all the controls on the form
For Each ctl In Me.Controls
' Check the tag property
If ctl.Tag = "RequiredField" Then
' Check this control has a value
If ctl = "" Or IsNull(ctl) Then
' No Value - Cancel the update event
Cancel = True
End If
End If
Next
' Check to see if a required field was blank and
inform the user
If Cancel = True Then
MsgBox "Please fill in all required fields.",
vbExclamation, "Information is missing"
End If
Many thanks,
Christine