How to enable a command button

crich21

Registered User.
Local time
Yesterday, 22:40
Joined
Jan 10, 2003
Messages
94
I am stumped on how I can enable a command button while typing in a field
I have frmunits that has 3 fields Year, Model, Vin#. I want the cmdwarranty button disabled unless there is something entered in on of these boxes. I currently have this
If Not IsNull(Year) Or Not IsNull(Model) Or Not IsNull(Vinnumber) Then
Me.cmdwarranty.Enabled = True
End If
But no matter what event I try I can't seem to make the button enable and disable correctly. The form is set for continuous and the cmdwarranty button is located in the form header which shouldn't matter. Also I will need to disable the button once someone moves to a new record. To do this I think all I need is the oncurrent event of the form to have this
If IsNull(Year) Or IsNull(Model) Or IsNull(Vinnumber) Then
Me.cmdwarranty.Enabled = False
End If

Can someone please help me with this.
 
Private Sub Form_Current()
If Me.NewRecord = True Then
Me!Cmdwarranty.Enabled = False
Exit Sub
End If
If IsNull(Me!Year) Then
ElseIf IsNull(Me!Model) Then
ElseIf IsNull(Me!VIN) Then
Me!Cmdwarranty.Enabled = False
Else
Me!Cmdwarranty.Enabled = True
End If
End Sub
 
Try this:
Put this code on the ONCURRENT Event
Code:
If IsNull(yourfield) Or IsNull(yourfield) Or IsNull(yourfield) Then
Me.Command6.Enabled = False
Else
Me.Command6.Enabled = True
End If

Then put this on the first textbox etc on the ONCHANGE Event:
Code:
If IsNull(yourfield) Then
Me.Command6.Enabled = False
Else
Me.Command6.Enabled = True
End If

Andy
 
I've tried both

I have tried both spacepro and billyr suggestions and something just isn't right. It's like the oncurrent event isn't working on either one of them. Maybe it's just me. I have posted the db if someone could take a look I would appreciate it.

Thank you
:confused:
 

Attachments

Last edited:
Take a look

Here's what I used to test mine. Its Access 2K. DAO
 

Attachments

This demo works

billyr said:
Here's what I used to test mine. Its Access 2K. DAO

Your demo you posted works I am not sure why mine won't. One thing I noticed on your demo that I need to work differently though is I only want the command button disabled if all three text boxes are null. I still don't completely understand vba so I am not sure how to change your code to fix this problem.
 
Ok

Here ya go. If these are the only 3 fields in your table, Access will not save a record if all 3 are null. Just in case the code checks them anyway. Hint; start looking at Access VB Help. There are a lot of examples. Any basic question will be answered there.
 

Attachments

Question

billyr said:
Here ya go. If these are the only 3 fields in your table, Access will not save a record if all 3 are null. Just in case the code checks them anyway. Hint; start looking at Access VB Help. There are a lot of examples. Any basic question will be answered there.


I don't mean to sound dumb but where is the Access VB help section you are referring to. Is it the same as the help section in Access xp?
 
Help help

Open the form in design view. Look at the form properties - events. Click the 3 dots to the right of OnCurrent to open visual basic. "Help" on that screen is what you want. Start with "Getting started". :)
 
Thank you

billyr said:
Open the form in design view. Look at the form properties - events. Click the 3 dots to the right of OnCurrent to open visual basic. "Help" on that screen is what you want. Start with "Getting started". :)

Thank you for all your help. I will get reading.
 

Users who are viewing this thread

Back
Top Bottom