Enable command button

S

Sue Wilkes

Hi All, I have on dirty behind my bound text boxes the following code.
Private Sub RegisterNumber_Dirty(Cancel As Integer)

'Enable SaveAddNewRec1 only if ALL required textboxes are dirty

If Me.AddNewRecIN.Enabled = True And Len(Me.DateReceived & vbNullString)
= 0 Then
ElseIf Me.AddNewRecOUT.Enabled = True And Len(Me.DateSent &
vbNullString) = 0 Then
ElseIf IsNull(Me.DeptCode) Then
ElseIf IsNull(Me.Designation) Then
ElseIf Me.AddNewRecIN.Enabled = True And Len(Me.ReceivedFrom &
vbNullString) = 0 Then
ElseIf Me.AddNewRecOUT.Enabled = True And Len(Me.SentTo &
vbNullString) = 0 Then
ElseIf IsNull(Me.CompanyNames) Then
ElseIf IsNull(Me.Subject) Then
ElseIf IsNull(Me.Hyperlink1) Then
Me.SaveAddNewRec1.Enabled = True
Me.SaveAddNewRec1.Visible = True
Me.SaveConfirm.Visible = True
This only enables the command button if all the required fields are complete
BUT only if I enter them in the tab order routine, if I deviate from this an
enter the data randomly then the command button does not appear. Could
someone please tell me where I'm going wrong. Many thanks Sue
 
J

Jeff Boyce

Sue

Are you saying that you have your code behind each text box? If so, and if
your user doesn't visit one of the text boxes, how would Access know what to
do?

Another approach might be to leave the command button enabled, but add your
validation routine into the command button first.

If a user clicks the command button without having filled all fields, you
can provide a message (MsgBox) and refuse to process the form, placing the
focus back into the "missing" value.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 

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

Similar Threads

Main Form, Sub-Form 3
Access Message 1
Data Validation & Cancel Exit Command 5
Back to Basics 1
OnExit driving me crazy 3
On close event Problem? 1
do while command button property is false 2
Error 2001 1

Top