Validate field for every record in table with a form (vb-code)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

This may be a simple question, but I seem to be stuck on it.
I've built a recordform where you can see and change all records in a table. On that form is a button to go to another form. Now what I want is that when you press that button, a specific field is validated over the entire table. That field is standard empty and should be filled in by the user for every record. So if the user exits the form and when that field is still empty in whichever record a messagebox with "yes" and "no" buttons should be displayed, something like: "Caution, not all records are adjusted. Are you sure you want to exit?"
When they press "yes" the form just closes, but when they press "no", the specific record with the empty field needs to be shown (so the user won't have to search for it).

Any help is greatly appreciated. Thanx in advance!!!!!!

Greetz Pain.
 
Here is a solution that filters the form so that it contains only the
records where the field is Null. These are the ones the user needs to fix.

If you apply the filter and there are no such records, you finish up at the
new record. So, it it's not a new record after you apply the filter, the
user needs to fix the filtered records:

Private Sub CheckAll_Click()
If Me.Dirty Then 'Save first.
Me.Dirty = False
End If
Me.Filter = "[MyField] Is Null"
Me.FilterOn = True
If Me.NewRecord Then
'go whereever.
Else
MsgBox "Records need fixing first."
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Pain said:
This may be a simple question, but I seem to be stuck on it.
I've built a recordform where you can see and change all records in a
table. On that form is a button to go to another form. Now what I want is
that when you press that button, a specific field is validated over the
entire table. That field is standard empty and should be filled in by the
user for every record. So if the user exits the form and when that field is
still empty in whichever record a messagebox with "yes" and "no" buttons
should be displayed, something like: "Caution, not all records are adjusted.
Are you sure you want to exit?"
When they press "yes" the form just closes, but when they press "no", the
specific record with the empty field needs to be shown (so the user won't
have to search for it).
 
Thanx, it works perfect.

Greetz, Sam


Allen Browne said:
Here is a solution that filters the form so that it contains only the
records where the field is Null. These are the ones the user needs to fix.

If you apply the filter and there are no such records, you finish up at the
new record. So, it it's not a new record after you apply the filter, the
user needs to fix the filtered records:

Private Sub CheckAll_Click()
If Me.Dirty Then 'Save first.
Me.Dirty = False
End If
Me.Filter = "[MyField] Is Null"
Me.FilterOn = True
If Me.NewRecord Then
'go whereever.
Else
MsgBox "Records need fixing first."
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Pain said:
This may be a simple question, but I seem to be stuck on it.
I've built a recordform where you can see and change all records in a
table. On that form is a button to go to another form. Now what I want is
that when you press that button, a specific field is validated over the
entire table. That field is standard empty and should be filled in by the
user for every record. So if the user exits the form and when that field is
still empty in whichever record a messagebox with "yes" and "no" buttons
should be displayed, something like: "Caution, not all records are adjusted.
Are you sure you want to exit?"
When they press "yes" the form just closes, but when they press "no", the
specific record with the empty field needs to be shown (so the user won't
have to search for it).
Any help is greatly appreciated. Thanx in advance!!!!!!

Greetz Pain.
 
Back
Top