Checking the records in table

Schlingel

Registered User.
Local time
Today, 04:56
Joined
Oct 26, 2006
Messages
32
Hi!
I really appreciate my being the part of this community. I also appreciate ur help. Thanks, i have already learned much.
Now i have a small problem and i am asking for ur help.
I have a form. The user can input hours (options group from 1 to 8), module (combobox, only list entries) and comment (combobox, user and list entries).
I have written the following code to check if the records with the hour are already in the table, so the user could have only one record for hour #1, one record for hour#2 etc. But somehow it checks only for hour#1. I don't know why. Could u help me, please?
Code:
Private Sub Form_AfterInsert()
Dim items As Long
Dim items2 As String
Dim items3 As Long
Dim adate As String
Dim adate1 As String
Dim adate2 As String
Dim adate3 As String
Set db = CurrentDb
Set rst = db.OpenRecordset("Nachweis")


adate1 = Format(Forms!Nachweis!Datum, "mm")
adate2 = Format(Forms!Nachweis!Datum, "dd")
adate3 = Format(Forms!Nachweis!Datum, "yyyy")
adate = adate1 & "/" & adate2 & "/" & adate3

items = DCount("[Stunde]", "Nachweis", "[Datum]= " & "#" & adate & "#" & "")
MsgBox items
If items = 0 Then
Me.Rahmen44.Value = 1
GoTo ENDE
Else: End If
items2 = DLookup("[Stunde]", "Nachweis", "[Datum]= " & "#" & adate & "#" & "" And "[Stunde]= '" & "Me.Rahmen44.Value" & "'")
MsgBox items2
If items <= 8 Then
    If items2 = Me.Rahmen44.Value Then
    MsgBox "Die Eingabe für diese Stunde existiert schon"
    Me.Rahmen44.Value = items2 + 1
    Else: End If
Else
MsgBox "Für diesen Tag haben Sie schon 8 Eingaben"
End If
ENDE:
End Sub
Rahmen44 is the name of my optionsgroup
As always, thanks in advance
 
Hi,

1. you don't seem to have any looping constructs, to cycle through the hourly tests, and increment your optiongroup value

2. do you really want to keep changing the value of your optiongroup by code. You can loop through values 1 to 8 by dimming an index within the afterinsert and then calling for index=1 to 8, etc

------------------------
put a breakpoint in the left margin of your code. click in the left margin - you will get a brown blob.

The code will suspend exceution and put you at the appropriate breakpoint when it hits it. You can now use F8 to step through your code a line at a time, so you can follow it carefully and see what it is actually doing.

Ideal for this.
 
Hi, gemma-the-husky!
Thanks for quick reply. I don't really understand what u mean with the second idea... But the thing i have to check is whether the user has already inputed the record for the hour checked in the optiongroup. I don't try to change the value of my optiongroup with this code. This very code could function properly if i only make it always check the last record in the table with DLookup function or sort the records in the table by date and hour
 
Last edited:

Users who are viewing this thread

Back
Top Bottom