Save subform record, open form, then go to new record

  • Thread starter steamngn via AccessMonster.com
  • Start date
S

steamngn via AccessMonster.com

Hello Gang!
I'm developing (or attempting to, anyway) an ID badge check in module for
class attendance. I have a main form bound to ATTENDANCE_HDR and a subform
bound to ATTENDANCE. The forms are linked on ATT_HDR_ID. In the subform is a
filed for STUDENT_ID. The main form has an OnTimer event to refresh the time
filter so that the check in screen is showing the current class. If I add a
student ID number to the subform STUDENT_ID control and press enter (similar
to what a barcode reader will do), The subform Before Update code pops up a
small confirmation form which closes after a few seconds. All of this is
working fine up until the confirmation form closes. The subform is still on
the current record, and then the main form On Timer event errors out trying
to insert the same record again. How can I get the subform (which loses focus
when the confirmation form opens) to go to a new record after the update?
Also, when a student enters an invalid ID or tries to sign in to the same
class twice, My code sets Cancel = True, but again the subform stays in the
current (Dirty?) record. I am stumped, and sure could use some guidance. Here
is the code for the Before Update on the subfrom:
Private Sub Form_BeforeUpdate(Cancel As Integer)
strSQL = "[STUDENT_ID]=" & Me!STUDENT_ID
strSQL2 = "[STUDENT_ID]=" & Me!STUDENT_ID & " And [ATT_HDR_ID]=" & Me!
ATT_HDR_ID
'check to see if student already signed in
If DCount("STUDENT_ID", "ATTENDANCE", strSQL2) > 0 Then
Cancel = True
'open confirmation form with 0,1,1 openargs
DoCmd.OpenForm "Confirmation", , , , , , "0|1|1"
'If student didn't sign in...
ElseIf DCount("STUDENT_ID", "ATTENDANCE", strSQL2) <= 0 Then
'Check that the Student ID is valid
If DCount("STUDENT_ID", "STUDENTS", strSQL) > 0 Then
RunCommand acCmdRecordsGoToNew
'valid check in-- open confirmation form with data openargs
DoCmd.OpenForm "Confirmation", , , , , , Me!STUDENT_ID & "|" & Me!
EVENT_ST_TIME & "|" & Me!EVENT_DESC
ElseIf DCount("STUDENT_ID", "STUDENTS", strSQL) <= 0 Then
Cancel = True
'Student Id invalid-- open confirmation form with 0,0,0 openargs
DoCmd.OpenForm "Confirmation", , , , , , "0|0|0"
End If
End If
End Sub

Thanks much in advance for any help!
Andy
 
S

steamngn via AccessMonster.com

An Update:
By removing this line:
RunCommand acCmdRecordsGoToNew
from the above code a valid student ID record enters ok and when the
confirmation form closes the subform is indeed at a new record. I just cannot
get it to work when we don't insert due to invalid/duplicate data.
Andy
Hello Gang!
I'm developing (or attempting to, anyway) an ID badge check in module for
class attendance. I have a main form bound to ATTENDANCE_HDR and a subform
bound to ATTENDANCE. The forms are linked on ATT_HDR_ID. In the subform is a
filed for STUDENT_ID. The main form has an OnTimer event to refresh the time
filter so that the check in screen is showing the current class. If I add a
student ID number to the subform STUDENT_ID control and press enter (similar
to what a barcode reader will do), The subform Before Update code pops up a
small confirmation form which closes after a few seconds. All of this is
working fine up until the confirmation form closes. The subform is still on
the current record, and then the main form On Timer event errors out trying
to insert the same record again. How can I get the subform (which loses focus
when the confirmation form opens) to go to a new record after the update?
Also, when a student enters an invalid ID or tries to sign in to the same
class twice, My code sets Cancel = True, but again the subform stays in the
current (Dirty?) record. I am stumped, and sure could use some guidance. Here
is the code for the Before Update on the subfrom:
Private Sub Form_BeforeUpdate(Cancel As Integer)
strSQL = "[STUDENT_ID]=" & Me!STUDENT_ID
strSQL2 = "[STUDENT_ID]=" & Me!STUDENT_ID & " And [ATT_HDR_ID]=" & Me!
ATT_HDR_ID
'check to see if student already signed in
If DCount("STUDENT_ID", "ATTENDANCE", strSQL2) > 0 Then
Cancel = True
'open confirmation form with 0,1,1 openargs
DoCmd.OpenForm "Confirmation", , , , , , "0|1|1"
'If student didn't sign in...
ElseIf DCount("STUDENT_ID", "ATTENDANCE", strSQL2) <= 0 Then
'Check that the Student ID is valid
If DCount("STUDENT_ID", "STUDENTS", strSQL) > 0 Then
RunCommand acCmdRecordsGoToNew
'valid check in-- open confirmation form with data openargs
DoCmd.OpenForm "Confirmation", , , , , , Me!STUDENT_ID & "|" & Me!
EVENT_ST_TIME & "|" & Me!EVENT_DESC
ElseIf DCount("STUDENT_ID", "STUDENTS", strSQL) <= 0 Then
Cancel = True
'Student Id invalid-- open confirmation form with 0,0,0 openargs
DoCmd.OpenForm "Confirmation", , , , , , "0|0|0"
End If
End If
End Sub

Thanks much in advance for any help!
Andy
 
S

steamngn via AccessMonster.com

Yet another update:
Ihave fiddled around with acCmdUndo, and I've gotten the subform to refresh
properly. NOW I have this issue in the main form event timer:
When the main form OnTimer fires, Set the form up:
Private Sub Form_Timer()
Me.Filter = "[EVENT_DAT] = #" & Format(Now(), "mm/dd/yyyy") & "# And DateAdd
('n',0,[EVENT_ST_TIME]) between #" & DateAdd("n", -5, Time()) & "# And #" &
DateAdd("n", 5, Time()) & "#"

Me.FilterOn = True

Me.Refresh
Me.sfmCheckIn.SetFocus
DoCmd.GoToRecord , , acNewRec
End Sub
Problem is, if there is a partial entry in the subform when the refresh
occurs, the code errors out with "cannot go to the specified record" from the
acNewRec line. How can I check to see if the subform is in this state? I
would think the best way is to see if the form is dirty, then undo before
going to new. This would force the user to reenter their ID to sign in, which
is Ok since to the user it would appear that the system just didn't take the
first entry at all.
Nothing like taking the ability to screw the system up away from the screwee!
:)
Andy said:
An Update:
By removing this line:
RunCommand acCmdRecordsGoToNew
from the above code a valid student ID record enters ok and when the
confirmation form closes the subform is indeed at a new record. I just cannot
get it to work when we don't insert due to invalid/duplicate data.
Andy
Hello Gang!
I'm developing (or attempting to, anyway) an ID badge check in module for
[quoted text clipped - 40 lines]
Thanks much in advance for any help!
Andy
 

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