enabling/disabling a command button based on event circumstances

D

Dean Welch

I want to disable a command button in a form until the "Autonumber" key has
been generated, and then after its been generated I want to re-enable the
command button.
 
T

tina

set the following code on the form's Current event, as

Me!CommandButton.Enabled = Not IsNull(Me!AutoNumberField)

that will take care of the command button as you move from record to record
in the form. but enabling the button immediately after the Autonumber is
generated in a new record is a bit more problematic. i tried using the
form's BeforeInsert event, and also its' Dirty event; in both cases,
apparently the autonumber is generated immediately *after* the code runs, so
it does no good.

if the user *always* enters data in the same control *first*, in a new
record, you could add the above code to the control's BeforeUpdate event.
but if that's not the case, the best you might be able to do is to either
add code to every control's BeforeUpdate event (clunky) or settle for
enabling the command button when the new record is saved, by adding code to
the form's BeforeUpdate event.

hth
 
T

tina

well, duh - my problem was tunnel vision. i used the same "toggle" code in
the BeforeInsert and Dirty events, when of course the property doesn't need
to be toggled at that point - it simply needs to be turned on. thanks for
catching my back, Lynn! :)
 

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