What event to use for checking table values on a form when record iscompleted?

R

raylopez99

What event should I use to check values entered into a new record on a
form? The easiest one for me is "On Click" for a particular textbox,
but it requires user input. For the form itself, from "AfterUpdate",
On Current and "Before Update" are candidate--which one? Or are there
others?

Also I plan to use this structure: (StockSymbol is a field in the
table bound to the form)

If Me.NewRecord Then <--When will this condition trigger?

ElseIf IsNull(Me.StockSymbol) Then

'STUFF TO CHECK HERE
Else
'OTHER STUFF
End If

Thanks!

RL

(BT--you're fired. And you won't get a favorable recommendation from
me for your next job).
 
K

Klatuu

To validate values entered in a form, there are two places to consider.
1. The control's Before Update event
2. The form's Before Update event

Which you use will depend on how the form behaves. If a particular control
has to have a valid value before other things can happen, then use the
control's event; otherwise, use the form's event.

The reason to use the form's Before Update is because there is no certainty
the user will ever enter the control or enter a value in it. The Before
Update event of a control only happens when a value has been entered.

The reason for the Before Update is because it can be canceled.

Me.NewRecord becomes true as soon as you create a new record. I would check
the value in the form's current event.
 
R

raylopez99

To validate values entered in a form, there are two places to consider.
1. The control's Before Update event
2. The form's Before Update event

Which you use will depend on how the form behaves.  If a particular control
has to have a valid value before other things can happen, then use the
control's event; otherwise, use the form's event.

The reason to use the form's Before Update is because there is no certainty
the user will ever enter the control or enter a value in it.  The Before
Update event of a control only happens when a value has been entered.

The reason for the Before Update is because it can be canceled.

Me.NewRecord becomes true as soon as you create a new record.  I would check
the value in the form's current event.


Thanks! Very helpful and timely as I'm coding it now...moving right
along now that I have the right syntax for Visual Basic, which I still
maintain has an awful default debugger. Know way should it have
allowed the following without screaming something during the compile.

RL

For example:

'Correct syntax:

If Not IsNull(Me.StockSymbol) Then
Str002G = Me.AcctID.Value
If Not IsNull(Me.AcctID) Then
Str001G = Me.StockSymbol.Value
End If
End If

replaces WRONG SYNTAX: will compile but will give lots of runtime
errors!

If (Me.StockSymbol.Text <> Null And Me.AcctID.Text <> Null ) Then

...

End If
 
J

John W. Vinson

What event should I use to check values entered into a new record on a
form? The easiest one for me is "On Click" for a particular textbox,
but it requires user input. For the form itself, from "AfterUpdate",
On Current and "Before Update" are candidate--which one? Or are there
others?

Current fires the instant the user navigates to the record in question, before
they've made any changes. BeforeUpdate fires when the user has completed work
on a record and attempts to save it - e.g. closing the form, moving off the
record, moving to a subform, moving from a subform back to a mainform,
explicitly saving the record with Ctrl-Enter, etc. etc. It has a Cancel
parameter so if you're doing validation, it's the one to use.

AfterUpdate (as the name implies) fires after the record has successfully been
written to disk.
Also I plan to use this structure: (StockSymbol is a field in the
table bound to the form)

Is there a control on the form with StockSymbol as its control source - a
combo box perhaps? If so, it would be best to reference the control rather
than the fieldname.
If Me.NewRecord Then <--When will this condition trigger?

NewRecord won't "trigger". It's just True if the record being edited is the
new record, rather than the user editing some record which was previously
saved to the table.
ElseIf IsNull(Me.StockSymbol) Then

'STUFF TO CHECK HERE
Else
'OTHER STUFF
End If

Thanks!

RL

(BT--you're fired. And you won't get a favorable recommendation from
me for your next job).

<eeep!> Who's BT and what did he do!?

John W. Vinson [MVP]
 
R

raylopez99

Current fires the instant the user navigates to the record in question, before
they've made any changes. BeforeUpdate fires when the user has completed work
on a record and attempts to save it - e.g. closing the form, moving off the
record, moving to a subform, moving from a subform back to a mainform,
explicitly saving the record with Ctrl-Enter, etc. etc.  It has a Cancel
parameter so if you're doing validation, it's the one to use.

AfterUpdate (as the name implies) fires after the record has successfully been
written to disk.


Is there a control on the form with StockSymbol as its control source - a
combo box perhaps? If so, it would be best to reference the control rather
than the fieldname.

Yes, I discovered this myself about combo boxes. What I ended up
doing is putting the warming on BeforeUpdate.
<eeep!> Who's BT and what did he do!?

Nothing, he just is a flamer that sometimes posts on this board. I
fired him from replying to me!

RL
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top