Setting Visible and Enabled

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form that shows an e-mail address and a seperate button to click to
send a message to that e-mail address. The problem is, sometimes users
haven't entered an e-mail address and I dont want the button to even appear,
thus set its visible and enabled properties to false, but my code isn't
working... here is what I have now where the field is called EMail and the
button is named Link. This is in the Form OnOpen Event and yields a 424
'Object Required' error when I try to open.

If [Forms]![frmPositions]! Is Null Then Me.Link.Enabled = False

I used to have the following:


Private Sub Form_Open(Cancel As Integer)
If Me.Email = "" Then GoTo NoMail
NoMail:
Me.Link.Enabled = False

End Sub

But that did nothing... I tried the code in both the OnOpen and OnLoad
properties and got the same results... any suggestons?
 
A form's recordset isn't available until the Load event, but you mention
that you've tried that also. However, even if that worked, it would only
work for the first record. For it to continue to work as you move from
record to record, you need to place the code in the form's Current event.

If Nz(Me.Email, "") = "" Then
Me.Link.Enabled = False
Else
Me.Link.Enabled = True
End If

By your description, I assume that Email is the name of the textbox holding
the email address and that Link is the name of the button. You also need to
place this code in the AfterUpdate event of the Email textbox so that if the
users adds or removes the email address, the button will react accordingly.
If [Forms]![frmPositions]! Is Null Then Me.Link.Enabled = False[/QUOTE]

This syntax for Is Null is used in queries, for VBA it would be
If IsNull([Forms]![frmPositions]![Email]) Then Me.Link.Enabled = False

However, the Nz() function in the top example will handle the value if it is
Null or "".


--
Wayne Morgan
MS Access MVP


[QUOTE="JAY BABCOCK"]
I have a form that shows an e-mail address and a seperate button to click
to
send a message to that e-mail address. The problem is, sometimes users
haven't entered an e-mail address and I dont want the button to even
appear,
thus set its visible and enabled properties to false, but my code isn't
working... here is what I have now where the field is called EMail and the
button is named Link. This is in the Form OnOpen Event and yields a 424
'Object Required' error when I try to open.

If [Forms]![frmPositions]![Email] Is Null Then Me.Link.Enabled = False

I used to have the following:


Private Sub Form_Open(Cancel As Integer)
If Me.Email = "" Then GoTo NoMail
NoMail:
Me.Link.Enabled = False

End Sub

But that did nothing... I tried the code in both the OnOpen and OnLoad
properties and got the same results... any suggestons?[/QUOTE]
 
JAY BABCOCK said:
I have a form that shows an e-mail address and a seperate button to
click to send a message to that e-mail address. The problem is,
sometimes users haven't entered an e-mail address and I dont want the
button to even appear, thus set its visible and enabled properties to
false, but my code isn't working... here is what I have now where the
field is called EMail and the button is named Link. This is in the
Form OnOpen Event and yields a 424 'Object Required' error when I try
to open.

If [Forms]![frmPositions]! Is Null Then Me.Link.Enabled = False

I used to have the following:


Private Sub Form_Open(Cancel As Integer)
If Me.Email = "" Then GoTo NoMail
NoMail:
Me.Link.Enabled = False

End Sub

But that did nothing... I tried the code in both the OnOpen and OnLoad
properties and got the same results... any suggestons?[/QUOTE]

The form's Open event is too soon. Try the Load event or the Current
event.

Also, if the Email textbox is blank, it's probably Null, and neither of
these:
[QUOTE]
If [Forms]![frmPositions]![Email] Is Null Then Me.Link.Enabled = False[/QUOTE]
[QUOTE]
If Me.Email = "" Then GoTo NoMail[/QUOTE]

.... is the right way to test that. Try something like:

Me.Link.Enabled = Not IsNull(Me.Email)
 

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


Back
Top