Re: trapping user's leaving new record b4 entring reqd data
- From: Ted <Ted@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 10 Feb 2006 07:07:26 -0800
hi allen,
i am at my desktop again...i coded the vba you proposed into the
'BeforeUpdate' event and things aren't going as planned. here are some of the
consituent parts of the puzzle.
on my form, there's an 'Add Record' button which launches the OnClick event
below:
Private Sub AddRecord_Click()
On Error GoTo Err_AddRecord_Click
Dim response As Integer
Forms("Screening Log").AllowAdditions = True
If Not Me.NewRecord Then DoCmd.GoToRecord , , acNewRec
Forms("Screening Log").AllowAdditions = False
Exit_AddRecord_Click:
Exit Sub
Err_AddRecord_Click:
MsgBox Err.description
Resume Exit_AddRecord_Click
End Sub
i put a debug brekapoint in the vba BeforeUpdate code i added (below):
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String
If IsNull(Me.StudyNumber) Then
Cancel = True
strMsg = strMsg & "Study Number is required." & vbCrLf
End If
If IsNull(Me.RegNumber) Then
Cancel = True
strMsg = strMsg & "Registration Number is required." & vbCrLf
End If
If IsNull(Me.On_Study_Date) Then
Cancel = True
strMsg = strMsg & "On Study Date is required." & vbCrLf
End If
If Cancel Then
strMsg = strMsg & "Complete the data or press <Esc> to undo your
entry."
MsgBox strMsg, vbExclamation, "Invalid Data"
End If
End Sub
and i notice that when i click the Add Record button the first 'place' it
goes to is the statement under this
If IsNull(Me.StudyNumber) Then
which (hovering over StudyNumber) tells me that StudyNumber is not null --
it's equial to the value of the control on the record i was viewing when i
clicked the cmdbtn! the same's true of the two other controls....so the tests
are never satisfied :-)
can you help me....i don't quite know why it goes to this event before
adding the new record?
-ted
"Allen Browne" wrote:
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:
- Re: trapping user's leaving new record b4 entring reqd data
- From: Allen Browne
- Re: trapping user's leaving new record b4 entring reqd data
- References:
- Re: trapping user's leaving new record b4 entring reqd data
- From: Allen Browne
- Re: trapping user's leaving new record b4 entring reqd data
- Prev by Date: Re: Programs for OCR
- Next by Date: Re: Export Query into Existing Table In Word
- Previous by thread: Re: trapping user's leaving new record b4 entring reqd data
- Next by thread: Re: trapping user's leaving new record b4 entring reqd data
- Index(es):
Loading