[Table] and ???

G

Guest

Okay

I know that I put brackets around table [name] but what about the contents of a drop down menu: here code that I have that is not working

Private Sub All_Total_AfterUpdate(

If [Task] = Null Then <---okay Task is a Drop Down Menu with several options (Should I use null?
[All_Total] = -1 <---I want this check box to show checked with Task has anything in i
Els
[All_Total] = 0
End I

End Sub
 
B

Brendan Reynolds

In VBA, nothing is ever equal to Null, not even another Null. Null
represents an unknown value. Is one unknown value equal to another? The
answer is unknown, i.e. Null.

What this means in practical terms is the statement "If Task = Null" will
return neither True nor False, but Null.

The solution is to use the IsNull() function rather than the = operator:

If IsNull(Task) Then
etc.

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

Walt said:
Okay,

I know that I put brackets around table [name] but what about the contents
of a drop down menu: here code that I have that is not working:
Private Sub All_Total_AfterUpdate()

If [Task] = Null Then <---okay Task is a Drop Down Menu with several options (Should I use null?)
[All_Total] = -1 <---I want this check box to show checked with Task has anything in it
Else
[All_Total] = 0
End If

End Sub
 
G

Guest

Instead of IsNull (because im having trouble figuring out) I tried this route, but my getting Total to produce a check automatically is not working

Private Sub Total_AfterUpdate(Cancel As Integer
If [Task] = A or B The
[Total] = -
Els
[Total] =
End I
End Sub
 
B

Brendan Reynolds

What problem are you having with IsNull()?

If "A" and "B" are possible values that may be selected from the combo box
(I'm assuming that when you said 'Drop down menu' you meant a combo box?)
then your "A or B" example would need to look something like this:

If Task = "A" Or Task = "B"

Without the quotes, VBA will assume that A and B are variable names. If you
had Option Explicit turned on, you'd get an error message telling you that
these variables were undeclared. Without Option Explicit, VBA 'helpfully'
creates variables with those names, with the Variant data type and a value
of Empty.

BTW: Square brackets are not usually required around control names in VBA,
unless the control name includes a space or other illegal character.

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

Walt said:
Instead of IsNull (because im having trouble figuring out) I tried this
route, but my getting Total to produce a check automatically is not working.
Private Sub Total_AfterUpdate(Cancel As Integer)
If [Task] = A or B Then
[Total] = -1
Else
[Total] = 0
End If
End Sub
 

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