Help with Event Code please

  • Thread starter Thread starter JohnB
  • Start date Start date
J

JohnB

Hi. When users edit a form I want to control their moving
to the next record, depending on what theyve done.

If they add content to either one of the fields
txtSubject1 or txtSubject2 but forget to add a value in
both of the fields txtCourse1 and txtCourse2, then they
are prevented from opening the next record and a message
like You Must Add Course1 and Course2 Info. appears. If
they dont add content to either txtSubject1 or txtSubject2
then they can progress to the next record.

What would the code look like and what Event should I use?
Im using Access 2003 on XP.

Many thanks, JohnB
 
JohnB,

How you do this will depend on whether you are using bound or unbound forms.
If you are using bound forms, the code should go in the Before Update events
for Course1 and Course2. I am assuming here that if txtSubject 1 has value
and txtSubject2 does not, then only Course1 would require data:

If Nz(Me.txtSubject1,"") <> "" And Nz(Me.Course1,"") = "" Then
Cancel = True
Msgbox "Blah Blah, Blah"
End If

If the form is unbound, then you will have to put similar logic in the event
where you save a record, for example, I usually use unbound forms, and I put
checks like that in the ON Click event of a SAVE command button.
 
Thanks for this reply. My forms are bound and actually
both Course1 and Course2 require data if either Subject1
or Subject2 get data. Is the code you quote meant to go in
the Before Update event for Course1? If so, bearing in
mind what Ive said earlier, what would the code be for
Course2. Thanks again for the help. JohnB
 
Then the code should probably go in the Before Update event of the form
If Nz(Me.txtSubject1,"") <> "" And Nz(Me.txtSubject2,"")<> "" then
if Nz(Me.Course1 = "" OrNz(Me.Course2,"") = "" then
do your error handling here
end if
endif
 
Back
Top