How to check continuous form fields

L

Lloyd

I have a tabbed form, when I switch from one tab to another, it checks to
make sure that none of the mandatory fields are missing. However the code
that checks the records on tab #1 (which is the code below after the elseif),
the code only checks the first record. I can not figure out how to modify
the code to get it to look at other records on the form that may be present.
Any suggestions on what modification I would need to make here would be
helpful.

thanks!

If TabCtl4 = 1 Then

Dim CkCtls As New Collection

CkCtls.Add "DRNo"
CkCtls.Add "DateOccd"
CkCtls.Add "TimeOccd"
CkCtls.Add "CaseType"
CkCtls.Add "Dispo"
CkCtls.Add "Location"
CkCtls.Add "City"
CkCtls.Add "Division"
'CkCtls.Add "Detective1"
CkCtls.Add "ShootingType"

Dim var As Variant

For Each var In CkCtls
If IsNull(Me(var)) Then
'Me(var).BackColor = 11468799 ' light yellow

MsgBox var & " Field MUST be completed", vbCritical +
vboko, "You left fields empty"
Me(var).BackColor = 255 ' Red
Me!TabCtl4.Value = 0

Else
'MsgBox "no fields are null"
'Me(var).BackColor = 16777215 ' white
End If
Next


ElseIf TabCtl4 = 4 Then

'TAB #1 continuous form - NEED TO CYCLE THROUGH ALL RECORDS ON FORM
Dim CkCtls1 As New Collection

CkCtls1.Add "LastName"
CkCtls1.Add "PersonType"
CkCtls1.Add "PersonCaseType"

Dim var1 As Variant

For Each var1 In CkCtls1
If IsNull([Forms]![frmMainEntry]![subfrmPersons](var1)) Then
'Me(var).BackColor = 11468799 ' light yellow

MsgBox var1 & " Field MUST be completed", vbCritical +
vboko, "You left fields empty"
[Forms]![frmMainEntry]![subfrmPersons](var1).BackColor =
255 ' Red
Me!TabCtl4.Value = 1

Else
'MsgBox "no fields are null"
'Me(var).BackColor = 16777215 ' white
End If
Next

Else

End If
 
L

Lloyd

Linq Adams via AccessMonster.com said:
Validation code to insure that required fields are populated has to be
executed before a record is saved. You don't validate more than one record at
a time! I think you need to rethink your approach here.

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000/2003

Message posted via AccessMonster.com


.
I have tried making fields required, but it doesnt always work as users dont
always select enter the field I need them to fill out. The code I have has
been working great on the first tab to prevent data loss, but on the 2nd tab
(tab 1) where they enter person information, it doesnt work well since its a
continuous form. I have tried various methods but none seem to work well
except through the method I use on tab 0 which is the code below so I have
expanded the code to work on Tab 1 and it works but just on the first record.
If you have another suggestion I would apprecaite your thoughts.
 
D

Daryl S

Lloyd -

I think you want to loop through the records, not the controls on the
subform.

Look up Help on the GoToRecord command:

DoCmd.GoToRecord acDataForm, "yourformname", acGoTo, i
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top