Re: trapping user's leaving new record b4 entring reqd data
- From: "Allen Browne" <AllenBrowne@xxxxxxxxxxxxxx>
- Date: Fri, 10 Feb 2006 06:50:51 +0800
Access fires the BeforeUpdate event of the *Form* (not control) just before
the record is saved. This is the only way to programmatically test whether
fields have been filled in. Cancel the event to prevent the save.
Example:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
If IsNull(Me.StudyNumber) Then
Cancel = True
strMsg = strMsg & "Study number required." & vbCrLf
End If
If IsNull(Me.RegNumber) Then
Cancel = True
strMsg = strMsg & "Reg number required." & vbCrLf
End If
'etc
If Cancel Then
strMsg = strMsg & "Complete the data, or press <Esc> to undo."
MsgBox strMsg, vbExclamation, "Invalid Data
End If
End Sub
Of course, you could achieve the same outcome without any code if you open
the table in design view and set the Required property of the field to yes.
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Ted" <Ted@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:48C99429-DED6-4341-A8E5-8BD1F3897171@xxxxxxxxxxxxxxxx
i created an add record button atop my a2k data entry form which uses the
following vba code:
Private Sub AddRecord_Click()
On Error GoTo Err_AddRecord_Click
Forms("Screening Log").AllowAdditions = True
If Not Me.NewRecord Then DoCmd.GoToRecord , , acNewRec
Me.StudyNumber.Value = "ENTRY REQUIRED"
Me.RegNumber.Value = "ENTRY REQUIRED"
Me.[On-Study Date].Value = #1/1/1900#
DoCmd.GoToControl "StudyNumber"
Forms("Screening Log").Dirty = False
Forms("Screening Log").AllowAdditions = False
Exit_AddRecord_Click:
Exit Sub
Err_AddRecord_Click:
MsgBox Err.description
Resume Exit_AddRecord_Click
End Sub
i don't want the user to be able to move away from this record until the
user has taken care of entering the data in the controls reg#, study# and
on-study date. i know this takes a msgbox and i know we have to trap for
the
failure on the user's part, the trick is identifying how to tell vba
that's
what the user's trying to do. i tried using the ".oldvalue" feature and
testing for the starting and ending values but that didn't seemt to fit. i
found a blurb about the '.newrecord' property value in the Help
documentation....is this the way to go?
.
- Follow-Ups:
- Prev by Date: Re: Insert OLEobject Into a field in a table programatically
- Next by Date: Re: turn off 'beep', msgbox?
- Previous by thread: Re: Insert OLEobject Into a field in a table programatically
- Next by thread: Re: trapping user's leaving new record b4 entring reqd data
- Index(es):