
Signature
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
All works great, Now next question?
Ned some help setting up the form. Have two tables:
1. Students Form and Demerits Form joined one to many
2. The demerit form is a subform with Date and I’ve placed the Option Group
box on the sub-form that has 3 buttons Present, Absent, Absent Unexcused.
When I press any of the choices I would like for the user to be unable to
duplicate the date of the attendance for the particular student. Say on
5/5/05 John Doe can be either Present, Absent or Absent Unexcused. Right now
I am able to enter records with the same date with different Option Group
choice causing duplicate date entry. Any help. Appreciate.
JPol
> > On my form I have an option group[Frame25] set to Present(1), Absent(2),
> > Unexcused(3). Present is a default. There are other fields on the form that I
[quoted text clipped - 15 lines]
> [StaffNr] = 0
> End If
Klatuu - 30 May 2006 13:39 GMT
In the Before Update event of the text box where you enter the date:
If Not IsNull(DLookup("[AttendanceDate]", "YourTableName", "[AttendanceDate]
= #" & Me.txtAttendanceDate & "#" Then
MsgBox "Attendance for " & Me.txtAttendanceDate & " Already Recorded"
Cancel = True
End If
[AttendanceDate] is the name of the field where the date is carried
YourTableName is the name of the table where the date is carried
Me.txtDate is the name of the text box control where you enter the date.
The code above will check to see if the date is already recorded. If the
DLookup does not return Null, that means the date is recorded. If so, the
message box will be displayed, the update will be canceled, and the cursor
will remain in the date control.
> All works great, Now next question?
> Ned some help setting up the form. Have two tables:
[quoted text clipped - 28 lines]
> > [StaffNr] = 0
> > End If
JPol - 31 May 2006 23:41 GMT
I have put the code as you have written, but gives me a error, due to
parenthesis ‘( 0r)’ not in correct place. Also lines may not be correctly
separated from line to line. Here are the names:
[AttendanceDate] is [School_Date], Table name is ‘tabDemerits’, Me.txtDate
is Me.School_Date
Could you please rewrite and post again.
Thanks
JPol
> In the Before Update event of the text box where you enter the date:
>
[quoted text clipped - 45 lines]
> > > [StaffNr] = 0
> > > End If
Klatuu - 01 Jun 2006 13:45 GMT
If Not IsNull(DLookup("[School_Date]", "tabDemerits", "[School_Date]
= #" & Me.txtAttendanceDate & "#") Then
MsgBox "Attendance for " & Me.School_Date & " Already Recorded"
Cancel = True
End If
> I have put the code as you have written, but gives me a error, due to
> parenthesis ‘( 0r)’ not in correct place. Also lines may not be correctly
[quoted text clipped - 54 lines]
> > > > [StaffNr] = 0
> > > > End If
JPol - 01 Jun 2006 14:39 GMT
First I pasted it into the after update event of the School_Date field on
the form. It gave me the following error: Compile Error: Expected List
Separator or ). Then I put a list separator ) and it all looks like this:
Private Sub School_Date_BeforeUpdate(Cancel As Integer)
If Not IsNull(DLookup("[School_Date]", "tabDemerits", "[School_Date]= #" &
Me.txtAttendanceDate & "#")) Then
MsgBox "Attendance for " & Me.School_Date & " Already Recorded"
Cancel = True
End If
It doesn’t work unfortunately,
JPol
> If Not IsNull(DLookup("[School_Date]", "tabDemerits", "[School_Date]
> = #" & Me.txtAttendanceDate & "#") Then
[quoted text clipped - 60 lines]
> > > > > [StaffNr] = 0
> > > > > End If
Klatuu - 01 Jun 2006 14:41 GMT
It goes in the Before Update event
> First I pasted it into the after update event of the School_Date field on
> the form. It gave me the following error: Compile Error: Expected List
[quoted text clipped - 74 lines]
> > > > > > [StaffNr] = 0
> > > > > > End If
JPol - 01 Jun 2006 16:41 GMT
It was in before update event of the School_Date field on the
subformAddDemerits.
It is doing nothing.
JPol
> It goes in the Before Update event
>
[quoted text clipped - 76 lines]
> > > > > > > [StaffNr] = 0
> > > > > > > End If
Klatuu - 01 Jun 2006 17:06 GMT
First, check this line. It is:
If Not IsNull(DLookup("[School_Date]", "tabDemerits", "[School_Date]= #" &
Me.School_Date & "#")) Then
I think I missed it when I rewrote the code.
Now, if that doesn't fiix it, then you need to put a breakpoint on the first
line of code in the Before Update event of School_Date. That is where the
code needs to be because you have entered a date and you want to see if it is
in the table before you allow the School_Date control to be updated.
So, set your breakpoint and step through the code checking the values of
your fields, controls, and variables.
I think it should be:
> It was in before update event of the School_Date field on the
> subformAddDemerits.
[quoted text clipped - 81 lines]
> > > > > > > > [StaffNr] = 0
> > > > > > > > End If
JPol - 02 Jun 2006 14:12 GMT
What do you mean - Break Point?
> First, check this line. It is:
> If Not IsNull(DLookup("[School_Date]", "tabDemerits", "[School_Date]= #" &
[quoted text clipped - 97 lines]
> > > > > > > > > [StaffNr] = 0
> > > > > > > > > End If
Klatuu - 02 Jun 2006 14:20 GMT
Open the code module in the VB editor. Put your cursor on the first line of
executable code in the procedure you want to debug. Press F9. You will see
the line change color. That means when the code is called, it will stop on
this line and it will be highlighted. To execute the line, press F8. You
can also position your cursor over a variable and be able to see the value.
You can also add Watches, which will present a window to allow you to see the
value of all objects.
You can step through the code line at a time to see what it is doing and
know exactly which line an error occurs on.
> What do you mean - Break Point?
>
[quoted text clipped - 99 lines]
> > > > > > > > > > [StaffNr] = 0
> > > > > > > > > > End If