Which event to use?

  • Thread starter Thread starter Niklas Östergren
  • Start date Start date
N

Niklas Östergren

Hi!

I have some buttons on a wizard form (<cmdAbort>, <cmdPrevious>, <cmdNext>
and <cmdFinish>) which I´d like to set enable property = True/False.

One criteria for setting cmdFinish.Enable = True is that a couple of the
fields in the form have any data so I use code like this:

If Not Me.txtFirstName & "" = "" And Not Me.txtLastName & "" = "" Then
cmdFinish.Enable = True
End If

I have totally 8 fields which need to have data before I enable <cmdFinish>.
The form is only allowed to have ONE record since it´s (I don´t know what
you call this type of table in english) a middle table only used to display
the entered or imported data to the user. The data will, after user have
fired <cmdFinish_Click> event or <cmdNext_Click> event, be copied to the
final tabels where the data will be stored. The data in this middle table
(tblNewMemberShipEntry) will then be deleted and the table will then be
empty.

Now to my Q:
In which event of the form shall this code fire? I have tryed Form_Dirty,
Form_AfterUpdate but it doesn´t fire. I have put a break verry early in my
code just to se if the code fire´s at all but it doesn´t.

TIA!
// Niklas
I have tryed to put this code in
 
Is there an event in a form which I can use for this or do I have to call a
sub procedure, in which I performe the check and set the enable property for
the cmd´s from each control´s LostFocus_Event or AfterUpdate_Event?

TIA!
// Niklas
 
Niklas Östergren said:
Is there an event in a form which I can use for this or do I have to
call a sub procedure, in which I performe the check and set the
enable property for the cmd´s from each control´s LostFocus_Event or
AfterUpdate_Event?

As I understand it, you want the cmdFinish button to become enabled when
several different controls have been filled in. Therefore, your idea is
correct -- you need to check for this state (all required controls
filled) each time any of the controls is updated. I would use these
controls' AfterUpdate events for this.

For convenience, you may want to write your code that tests this as a
function in the General section of the form's module:

Function EnableDisableFinishButton()

Me!cmdFinish.Enabled =
Not (IsNull(Me!txtTextbox1) Or _
IsNull(Me!txtTextbox2) Or _
IsNull(Me!txtTextbox3) Or _
IsNull(Me!txtTextbox4) Or _
IsNull(Me!txtTextbox5))

End Function

That way, you could just select all the text boxes at once, bring up
their combined property sheet, and enter this on the AfterUpdate event
property line:

=EnableDisableFinishButton()
 
OK!

Thank´s a lot Dirk! I have followed your recommendation and wrote a
sub in the general section of the form and it work´s well.

Thank´s for helping me out!

// Niklas
 
Back
Top