G
Guest
Hello,
I have a database of clinical patient records that is generally working
well, but does not alert the data entry person if they have entered in a
record w/ a duplicate 'key'. I check to see (in Sub 'Next_Click' below) to
see if certain required fields are filled in, and, if they are, then the
'Next Form' Command Button operates Sub 'OpenNextForm'-- also below, which
opens the next form in the 'series'. The user gets a nice error message if
one of the required fields is not filled in, but if they hit the 'Next Form'
Command Button and have entered in a record with a duplicate 'key', the user
gets no error message and moves on to the next form. Access does not save
the record (as it shouldn't), but I need the data entry person to be alerted
that they have just attempted to enter a record w/ a duplicate 'key'. The
only time they get an error message ab/ the duplicate 'key' is when they
click on the 'x' in the upper-right corner of the window. What can I add to
the existing code below, so the data entry person is alerted if there is a
duplicate 'key'? Thank you!
Private Sub Next_Click()
On Error GoTo Err_Next_Click
If Len(Me.site.Value & "") = 0 Then
MsgBox "You must enter a value into Site Number."
Me.site.SetFocus
ElseIf Len(Me.id.Value & "") = 0 Then
MsgBox "You must enter a value into Patient Number."
Me.id.SetFocus
ElseIf Len(Me.ptin.Value & "") = 0 Then
MsgBox "You must enter a value into Patient Initials."
Me.ptin.SetFocus
ElseIf Len(Me.data1_init.Value & "") = 0 Then
MsgBox "You must enter a value into Data Entry 1 Initials."
Me.data1_init.SetFocus
Else
Call OpenNextForm(Me.Name)
End If
Exit_Next_Click:
Exit Sub
Err_Next_Click:
DoCmd.Close acForm, Me.Name
Resume Exit_Next_Click
End Sub
Sub OpenNextForm(strName As String)
Dim intOrder As Integer, frmName As String
On Error GoTo OpenNextForm_Err
intOrder = DLookup("[FormOrder]", "LU_Forms", "[FormName]= '" & strName
& "'")
frmName = DLookup("[FormName]", "LU_Forms", "[FormOrder]= " & intOrder
+ 1)
If Not IsNull(frmName) Then
DoCmd.OpenForm frmName, , , "[id] = Forms.fScrEligCriteria.id"
'DoCmd.OpenForm frmName, , , , acAdd
End If
DoCmd.Close acForm, strName
OpenNextForm_Err:
'MsgBox Err.Description
Resume Next
End Sub
I have a database of clinical patient records that is generally working
well, but does not alert the data entry person if they have entered in a
record w/ a duplicate 'key'. I check to see (in Sub 'Next_Click' below) to
see if certain required fields are filled in, and, if they are, then the
'Next Form' Command Button operates Sub 'OpenNextForm'-- also below, which
opens the next form in the 'series'. The user gets a nice error message if
one of the required fields is not filled in, but if they hit the 'Next Form'
Command Button and have entered in a record with a duplicate 'key', the user
gets no error message and moves on to the next form. Access does not save
the record (as it shouldn't), but I need the data entry person to be alerted
that they have just attempted to enter a record w/ a duplicate 'key'. The
only time they get an error message ab/ the duplicate 'key' is when they
click on the 'x' in the upper-right corner of the window. What can I add to
the existing code below, so the data entry person is alerted if there is a
duplicate 'key'? Thank you!
Private Sub Next_Click()
On Error GoTo Err_Next_Click
If Len(Me.site.Value & "") = 0 Then
MsgBox "You must enter a value into Site Number."
Me.site.SetFocus
ElseIf Len(Me.id.Value & "") = 0 Then
MsgBox "You must enter a value into Patient Number."
Me.id.SetFocus
ElseIf Len(Me.ptin.Value & "") = 0 Then
MsgBox "You must enter a value into Patient Initials."
Me.ptin.SetFocus
ElseIf Len(Me.data1_init.Value & "") = 0 Then
MsgBox "You must enter a value into Data Entry 1 Initials."
Me.data1_init.SetFocus
Else
Call OpenNextForm(Me.Name)
End If
Exit_Next_Click:
Exit Sub
Err_Next_Click:
DoCmd.Close acForm, Me.Name
Resume Exit_Next_Click
End Sub
Sub OpenNextForm(strName As String)
Dim intOrder As Integer, frmName As String
On Error GoTo OpenNextForm_Err
intOrder = DLookup("[FormOrder]", "LU_Forms", "[FormName]= '" & strName
& "'")
frmName = DLookup("[FormName]", "LU_Forms", "[FormOrder]= " & intOrder
+ 1)
If Not IsNull(frmName) Then
DoCmd.OpenForm frmName, , , "[id] = Forms.fScrEligCriteria.id"
'DoCmd.OpenForm frmName, , , , acAdd
End If
DoCmd.Close acForm, strName
OpenNextForm_Err:
'MsgBox Err.Description
Resume Next
End Sub