disable controls until data is verified

M

Mark Kubicki

I have a frmDataEntry, which has on it (along with many other controls and
data entry fields) these three (3) items:
txtManufacturer - text, box; its default value on a new record is
nothing (null?)
txtCatalogNo - text box; its default value on a new record is
nothing (null?)
also, it should not be active until a value
has been entered in txtManufacturer
cmdAppNotes - command button; it should be disabled untill values
have been entered in BOTH txtManufacturer and txtCatalogNo

to this end I have entered the following code behind these envents (but, it
is not always effective):

Form_Open()

If Len(Nz(Me.txtManufacturer)) > 0 Then
Me.txtCatalogNo.Enabled = True
Else
Me.txtCatalogNo.Enabled = False
End If

If Len(Nz(Me.txtCatalogNo)) > 0 Then
Me.cmdAppNotes.Enabled = True
Else
Me.cmdAppNotes.Enabled = False
End If

with similar coding added behind the events: form_current(),
txtManufacturer_afterupdate(), txtCatalogNo_afterupdate()

any suggestions will be greatly (as always) appreciatd,
Mark
 
G

Graham Mandeno

Hi Mark

First, use Form_Current, not Form_Open. Presumable you want these controls
to be initially enabled/disabled for every record you visit, not just when
the form opens.

Second, use the AfterUpdate events of the two textboxes to check their new
values and determine the new enabled/disabled states of the other controls.

Third, make sure the control you are disabling does not have the focus,
otherwise you will get an error. For example:

If Me.ActiveControl is Me.txtCatalogNo Then Me.txtManufacturer.SetFocus
Me.txtCatalogNo.Enabled = False
 
M

Mark Kubicki

thanks,
I've got all that in place; yet when I advance to a new record (presumably,
all of the fields are blank); the controls's status's do not change.

- If in the previous record, they were enabled, they remain that way; if
they were not, they stay disabled...
They are behaving correctly, when I move to a different exisitng record.

mark


Graham Mandeno said:
Hi Mark

First, use Form_Current, not Form_Open. Presumable you want these
controls to be initially enabled/disabled for every record you visit, not
just when the form opens.

Second, use the AfterUpdate events of the two textboxes to check their new
values and determine the new enabled/disabled states of the other
controls.

Third, make sure the control you are disabling does not have the focus,
otherwise you will get an error. For example:

If Me.ActiveControl is Me.txtCatalogNo Then Me.txtManufacturer.SetFocus
Me.txtCatalogNo.Enabled = False

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Mark Kubicki said:
I have a frmDataEntry, which has on it (along with many other controls and
data entry fields) these three (3) items:
txtManufacturer - text, box; its default value on a new record is
nothing (null?)
txtCatalogNo - text box; its default value on a new record is
nothing (null?)
also, it should not be active until a
value has been entered in txtManufacturer
cmdAppNotes - command button; it should be disabled untill values
have been entered in BOTH txtManufacturer and txtCatalogNo

to this end I have entered the following code behind these envents (but,
it is not always effective):

Form_Open()

If Len(Nz(Me.txtManufacturer)) > 0 Then
Me.txtCatalogNo.Enabled = True
Else
Me.txtCatalogNo.Enabled = False
End If

If Len(Nz(Me.txtCatalogNo)) > 0 Then
Me.cmdAppNotes.Enabled = True
Else
Me.cmdAppNotes.Enabled = False
End If

with similar coding added behind the events: form_current(),
txtManufacturer_afterupdate(), txtCatalogNo_afterupdate()

any suggestions will be greatly (as always) appreciatd,
Mark
 

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