Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Subform field AND/OR Form BeforeUpdate Event not working...?

136 views
Skip to first unread message

KathyB

unread,
Jun 4, 2003, 11:08:51 AM6/4/03
to
I have a subform where I need to ensure that certain fields are not
null. I've tried the following code as both the BeforeUpdate event on
the Hours field, and on the BeforeUpdate event on the subform
itself...nothing happens...it allows me to add the record anyway with
no error message and not effect of the Cancel command. Any clues
appreciated...as always. Thank you. --Kathy

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me![cboActivityType]) Or IsNull(Me![cboTransActivity])
Or IsNull(Me![cboTransType]) Then
MsgBox "All fields are required...Thank you.", vbOKOnly,
"Incomplete Data"
Cancel = True
End If
End Sub

Allen Browne

unread,
Jun 4, 2003, 11:17:32 AM6/4/03
to
The BeforeUpdate event of the form is the right one to use.
Are you certain that the form's Before Update property is set to
[Event Procedure]
If not the code may not be running.

In any case, it might be better to open the table in design view and set the
Required property to Yes for all 3 fields. That doesn't require any code,
and works anywhere (not just in the form).

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to the newsgroup. (Email address has spurious "_SpamTrap")

"KathyB" <KathyB...@attbi.com> wrote in message
news:75e8d381.03060...@posting.google.com...

Kathy Burke

unread,
Jun 4, 2003, 2:58:21 PM6/4/03
to
Thanks Allen. I will set the table fields instead. I just really
wondered why it didn't kick-off...it is set to event procedure. I do
have some other events on fields in the subform record...I'm not too
clear on the in's and out's of event firing order. Would the following
negate my Form BeforeUpdate event? Would the .refresh command do it?

Just wondering...for now, I will change table fields!

thanks again.

Private Sub Hours_AfterUpdate()
[Forms]![frmTimeRecord].Refresh
[Forms]![frmTimeRecord]![frmTimeCardHours2].SetFocus
DoCmd.GoToRecord , , acLast
Me![Comment].SetFocus
End Sub

KathyBurke

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Kathy Burke

unread,
Jun 4, 2003, 3:18:23 PM6/4/03
to
Allen,

I just changed the 3 table fields to Required = Yes and it had no effect
on my form entry...it let me skip the fields and go on to the next
record!

I'm simply using a form/subform combination (with parent/child
relationship on an ID field). The subform source is the actual table.

Any clues appreciated...I've never seen this happen before.

Allen Browne

unread,
Jun 4, 2003, 9:29:14 PM6/4/03
to
The Refresh may silently fail to save the record, but setting focus to the
subform won't succeed if the main form record can't be saved.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to the newsgroup. (Email address has spurious "_SpamTrap")

"Kathy Burke" <anon...@devdex.com> wrote in message
news:3ede414d$0$204$7586...@news.frii.net...

Allen Browne

unread,
Jun 4, 2003, 9:39:54 PM6/4/03
to
Kathy, something else is wrong here.

If these are Access tables, JET won't let you save the record if one of the
required fields is not supplied.

If the tables are attached from another mdb, you need to set the fields'
Required property in the back end.

It is just remotely possible that you have a corruption here, but I doubt
that's it. Tools | Database Utilities | Compact and Repair. Make sure you do
that in the back end if the tables are attached.

You could add a Debug.Print statement to the top of your Form_BeforeUpdate
event to indicate if the event is firing at all. However, my guess is that
some other factor is at play here: it is extremely unlikely that you have
both a corrupted set of tables and a corrupted module for your form.


--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to the newsgroup. (Email address has spurious "_SpamTrap")

"Kathy Burke" <anon...@devdex.com> wrote in message

news:3ede45fe$0$199$7586...@news.frii.net...

Kathy Burke

unread,
Jun 5, 2003, 11:08:25 AM6/5/03
to
Very weird problem. Very straightforward db design. No back end (users
won't allow it!), direct parent/child link (one-to-many), code opens the
main form, auto fills a couple of fields, then user enters info in
subform records, also tried compact, etc....a mystery to me...

I ended up going back to using a BeforeUpdate event on the subform, but
broke up the IF statement into separate checks of each field, if the
field is null, it then gives a msgbox and does an Exit Sub to force the
user to complete the field, next attempt to leave the record continues
to examine each required field, etc. This works for some reason where
the combined IF statement did not. Maybe something to do with my requery
statements on some of the fields (all combo boxes)? Anyhow, found a way
around it, but will remain confused about the table fields required =
yes problem.

Thanks again for all your help, Allen.

Kathy

0 new messages