Hi Kenny:
I apologize for not getting back sooner; I've been on call the past few
nights (I'm a physician). I accidentally left out a lot of your code in my
just saved response- so ignore it. Here's the complete code.
First of all, before we begin, it would be easier to go to each textbox
control's tag property and add something like "ChkNull". This way when you
wish to check for nulls, you don't have to have a zillion If... End If
statements. All you would need to do is to add the following code to access
all of your controls:
Dim c As Object
For Each c in Me.Controls
If c.Tag = "ChkNull" Then
strRqdMsg = strRqdMsg & vbCrLf & c.Name
End If
Next 'c
Easy huh? Anyhow, let's clean up your code...
therefore the docmd(s) save record and go to newrecord are not completed.
Actually it is better that the beforeupdate event kicks in first, as you
want to check for null fields and thus allow the user to add information to
them, right? The 3 major events are as such:
1) check to see if the IsDirty event is true, and if so
2) check for null fields, and if none then
3) save record, and if there aren't duplicate key fields
4) ask the user if he wants to add another record, then invoke
the yes/no msgbox event and route appropriately.
Ok, here's how I would write the code- I would just dump it all in the
clickbutton's OnClick event. I've taken the liberty of adding error checking
for duplicate values. I've also added a few "Exit Sub" statements and added
"... and a New One Added" to your MsgBox statement (to let the user know
that he's on a new record). It should theoretically work well. Let me know
if you get any bugs:
Option Compare Database
Dim intanswer2 As Integer
Dim c As Object
Dim strRqdMsg As String
Option Explicit
Private Sub Command8_Click()
On Error GoTo CheckIndex_Error
If Me.Dirty = False Then
MsgBox "You Can't Save This Record - No Data Entry Was Made!",
vbInformation, "UHS"
DoCmd.GoToControl "MRN"
Exit Sub
Else
strRqdMsg = "The Following Required Field(s) Were Left Blank!"
For Each c in Me.Controls
If c.Tag = "ChkNull" Then
strRqdMsg = strRqdMsg & vbCrLf & c.Name
End If
Next
If Len(strRqdMsg) > 48 Then
MsgBox strRqdMsg
pintCancel = True
Exit Sub
End If
DoCmd.RunCommand acCmdSaveRecord
intanswer2 = MsgBox("Do You Have Another Entry To Make?", vbYesNo)
Select Case intanswer2
Case vbYes
MsgBox "Your Record Has Been Saved, and a New One Added - Please Continue.",
vbInformation, "UHS"
DoCmd.GoToRecord , , acNewRec
DoCmd.GoToControl "MRN"
Case vbNo
DoCmd.RunCommand acCmdSaveRecord
DoCmd.GoToControl "cmdReturnToMainMenu"
MsgBox "Click Return To Main Menu Button To Exit!", vbInformation, "UHS"
End Select
Exit Sub
CheckIndex_Error:
' here we check and trap for any possible identical key field value records
If Err.Number = 3022 Then
MsgBox "Duplicate record. We'll delete the lower valued record."
Me.Undo
Else
MsgBox Err.Number & " " & Err.Description, , "Private Sub CheckIndex()"
End If
Exit Sub
End Sub
------------------------------------
Regards,
Al
Kenny G said:
Al,
Many thanks for your response. I probably need to cut and paste the
original code - see below. The beforeupdate event kicks in before the
actual record is saved therefore the docmd(s) save record and go to
newrecord are not completed.