Button not working

L

Leslie Isaacs

Hello All

I have a button with the following OnClick event:

If [Forms]![frm payments]![payment date].Value Is Null Then
[accounting month].ForeColor = vbRed
[accounting month].BackStyle = 1
[accounting month].BackColor = 65535
Else
[accounting month].ForeColor = 0
[accounting month].BackStyle = acNormal
[accounting month].BackColor = 16777215
End If

but each time I try to run this I get "Runtime error 424 - Object required",
with the first line of the condition (starting with "If") highlighted in
yellow.
I have tried with and without the [Forms]![frm payments]! in front of the
[payment date] part, and also with and without the .Value after [Payment
date], but always with the same result.

My VB skills are not great (obviously!) but I thought I was up to this.

I would be very grateful for any help.
Thanks
Les
 
R

Rick B

Why not simply use conditional formatting to have the value change in
appearance automatically? Why click a button to see if the value should be
highlighted?
 
S

Sandra Daigle

You have to use the IsNull function to test for the null value.

IF isnull([Forms]![frm payments]![payment date].Value) Then

The keyword "is" is used to compare to object variables - hence the error.
 
L

Leslie Isaacs

Rick
I was intending to use the code as the AfterUpdate event of the field: the
button was just a convenient way to test it first.
I wasn't sure I could use expressions with DLookup, etc., in conditional
formatting: how would I do that?
Thanks for your help.
Les


Rick B said:
Why not simply use conditional formatting to have the value change in
appearance automatically? Why click a button to see if the value should
be highlighted?


--
Rick B



Leslie Isaacs said:
Hello All

I have a button with the following OnClick event:

If [Forms]![frm payments]![payment date].Value Is Null Then
[accounting month].ForeColor = vbRed
[accounting month].BackStyle = 1
[accounting month].BackColor = 65535
Else
[accounting month].ForeColor = 0
[accounting month].BackStyle = acNormal
[accounting month].BackColor = 16777215
End If

but each time I try to run this I get "Runtime error 424 - Object
required", with the first line of the condition (starting with "If")
highlighted in yellow.
I have tried with and without the [Forms]![frm payments]! in front of the
[payment date] part, and also with and without the .Value after [Payment
date], but always with the same result.

My VB skills are not great (obviously!) but I thought I was up to this.

I would be very grateful for any help.
Thanks
Les
 
L

Leslie Isaacs

Hello Sandra

Eurika! (if that's how you spell it) - IsNull is the answer!
Aren't these newsgroups great!

Many thanks
Les


Sandra Daigle said:
You have to use the IsNull function to test for the null value.

IF isnull([Forms]![frm payments]![payment date].Value) Then

The keyword "is" is used to compare to object variables - hence the error.

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.


Leslie said:
Hello All

I have a button with the following OnClick event:

If [Forms]![frm payments]![payment date].Value Is Null Then
[accounting month].ForeColor = vbRed
[accounting month].BackStyle = 1
[accounting month].BackColor = 65535
Else
[accounting month].ForeColor = 0
[accounting month].BackStyle = acNormal
[accounting month].BackColor = 16777215
End If

but each time I try to run this I get "Runtime error 424 - Object
required", with the first line of the condition (starting with "If")
highlighted in yellow.
I have tried with and without the [Forms]![frm payments]! in front of
the [payment date] part, and also with and without the .Value after
[Payment date], but always with the same result.

My VB skills are not great (obviously!) but I thought I was up to
this.
I would be very grateful for any help.
Thanks
Les
 
R

Rick B

I don't see any Dlookup stuff in your code. Your code simply says "If
Payment Date is null, then make the Accounting month field red and bold."
That is easy to do in conditional formatting.

As posted in another response though, you need to use IsNull(....



--
Rick B



Leslie Isaacs said:
Rick
I was intending to use the code as the AfterUpdate event of the field: the
button was just a convenient way to test it first.
I wasn't sure I could use expressions with DLookup, etc., in conditional
formatting: how would I do that?
Thanks for your help.
Les


Rick B said:
Why not simply use conditional formatting to have the value change in
appearance automatically? Why click a button to see if the value should
be highlighted?


--
Rick B



Leslie Isaacs said:
Hello All

I have a button with the following OnClick event:

If [Forms]![frm payments]![payment date].Value Is Null Then
[accounting month].ForeColor = vbRed
[accounting month].BackStyle = 1
[accounting month].BackColor = 65535
Else
[accounting month].ForeColor = 0
[accounting month].BackStyle = acNormal
[accounting month].BackColor = 16777215
End If

but each time I try to run this I get "Runtime error 424 - Object
required", with the first line of the condition (starting with "If")
highlighted in yellow.
I have tried with and without the [Forms]![frm payments]! in front of
the [payment date] part, and also with and without the .Value after
[Payment date], but always with the same result.

My VB skills are not great (obviously!) but I thought I was up to this.

I would be very grateful for any help.
Thanks
Les
 

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