hi tina,
i am at my desktop again...i coded some vba 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
tina said:
sounds like you're talking about validating data before saving a record.
that's usually done in the form's BeforeUpdate event procedure. you test for
invalid data, and if you find it, then you Cancel the Update event. the
current record keeps the focus until you 1) enter or correct the invalid
data, or 2) press Esc once or twice to erase all edits to the currect
record, or 3) close the form *without* saving the record. for example, say
you require a company name in a certain field before saving the record. you
could use the following code, as
If IsNull(Me!CompanyName) Then
Cancel = True
MsgBox "Enter the company name, please."
End If
since the above code runs in the BeforeUpdate event, and your GoToRecord
code probably runs elsewhere, perhaps on a command button's Click event,
cancelling the record update may cause the GoToRecord code to err out. if
so, you can trap the error code and handle it so that the user is none the
wiser.
hth
Ted said:
what i am trying to do is KEEP the user on the same record when a certain
condition i test for in my 'if' statement's satisfied. maybe this is the
subject of a new thread, but suppose you DON'T want the docmd.gotorecord
command to take you to another record? is there some way to have the
value
of
the offset equal 0 (zero). i've tried this but nothing's working just
yet?
in
case it'd help to know my rationale, when my user hits the 'add record'
command, another one is generated with gentle reminders that fields i've
preopulated with 'Entry Required' messages need to get entered before sailing
off to another record. i want to lock this down so that those fields
must
get
completed.
:
Thank you!
:
After adding the new record, set the focus to another field
DoCmd.GoToRecord , , acNewRec
Me.[Field name].SetFocus
--
\\// Live Long and Prosper \\//
BS"D
:
I have a command button that I use to create a new record but I
want
to also
be able to have it go to a certain field when a new record is created.
Wouldn't this be as simple as adding a "DoCmd.GoToControl"
function?
I tried
that and it didn't work. I have the "DoCmd.GoToRecord , ,
acNewRec"
working