Populate an unbound check box

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

Guest

Hi,

I would like to populate an unbound check box based on a if > then > else
test.
My current (incorrect) code is on the on_current event of my form and is as
follows.

If
Me.LicenceGranted < #7/1/2002# And Me.LicenceSurrendered Is Null Or
Me.LicenceGranted < #7/1/2002# And Me.LicenceSurrendered >= #7/1/2001# Then
Me.chk2001_02.Value = Checked
Else
Me.chk2001_02.Value = Unchecked
End If

I am getting an error that there is an if statement without an end if.
Have tried many combinations but am getting same error.
A little help on why my structure is incorrect would be most welcomed.

Thanks
 
Dylan said:
Hi,

I would like to populate an unbound check box based on a if > then >
else test.
My current (incorrect) code is on the on_current event of my form and
is as follows.

If
Me.LicenceGranted < #7/1/2002# And Me.LicenceSurrendered Is Null Or
Me.LicenceGranted < #7/1/2002# And Me.LicenceSurrendered >=
#7/1/2001# Then Me.chk2001_02.Value = Checked
Else
Me.chk2001_02.Value = Unchecked
End If

I am getting an error that there is an if statement without an end if.
Have tried many combinations but am getting same error.
A little help on why my structure is incorrect would be most welcomed.

Do you have that test all on one line? If not you need line continuation
characters added.

If (Me.LicenceGranted < #7/1/2002# _
And Me.LicenceSurrendered Is Null) _
Or (Me.LicenceGranted < #7/1/2002# _
And Me.LicenceSurrendered >= #7/1/2001#) Then
Me.chk2001_02.Value = Checked
Else
Me.chk2001_02.Value = Unchecked
End If
 
Hi,

Now have the followng code

If (Me.LicenceGranted < #7/1/2002# _
And Me.LicenceSurrendered Is Null) _
Or (Me.LicenceGranted < #7/1/2002# _
And Me.LicenceSurrendered >= #7/1/2001#) Then
Me.chk2001_02.Value = True
Else
Me.chk2001_02.Value = False
End If

and am getting an error ":Error 424 ... Object Required"

Note: I have changed the values to true and false. I am not sure if this is
correct.

Thanks
Dylan
 
Hi,

I would like to populate an unbound check box based on a if > then > else
test.
My current (incorrect) code is on the on_current event of my form and is as
follows.

If
Me.LicenceGranted < #7/1/2002# And Me.LicenceSurrendered Is Null Or
Me.LicenceGranted < #7/1/2002# And Me.LicenceSurrendered >= #7/1/2001# Then
Me.chk2001_02.Value = Checked
Else
Me.chk2001_02.Value = Unchecked
End If

I am getting an error that there is an if statement without an end if.
Have tried many combinations but am getting same error.
A little help on why my structure is incorrect would be most welcomed.

Thanks


Everything from If through Then in your code should all be on one
line, unless you use the line continuation characters (space_).
With multiple And Or's it might be wise to surround the wanted
combinations with parenthesis, as there may be more than 1 possible
combination which may lead to different results.

Also, Check box values are either =True or False, Yes or No, On or
Off, or -1 or 0 (not Checked or Unchecked).

Try (with everything between the If and the Then on one line) ...

If (Me.LicenceGranted < #7/1/2002# And Me.LicenceSurrendered Is Null)
Or (Me.LicenceGranted < #7/1/2002# And Me.LicenceSurrendered >=
#7/1/2001#) Then
Me.chk2001_02 = True
Else
Me.chk2001_02 = False
End If
 
Dylan said:
Hi,

Now have the followng code

If (Me.LicenceGranted < #7/1/2002# _
And Me.LicenceSurrendered Is Null) _
Or (Me.LicenceGranted < #7/1/2002# _
And Me.LicenceSurrendered >= #7/1/2001#) Then
Me.chk2001_02.Value = True
Else
Me.chk2001_02.Value = False
End If

and am getting an error ":Error 424 ... Object Required"

Instead of "Is Null" which is for use in queries, use the IsNull() VBA
fiunction.
 
Thanks Rick (and fred), Excellent. Code now working utilising the IsNull()
Function, and tidied up with the code line continuation.

'-----------Code now------------------

If (Me.LicenceGranted < #7/1/2002# And IsNull(Me.LicenceSurrendered)) _
Or (Me.LicenceGranted < #7/1/2002# _
And Me.LicenceSurrendered >= #7/1/2001#) Then
Me.chk2001_02.Value = True
Else
Me.chk2001_02.Value = False
End If

' ----------end code

Regards
Dylan
 
Thanks Rick (and fred), Excellent. Code now working utilising the IsNull()
Function, and tidied up with the code line continuation.

'-----------Code now------------------

If (Me.LicenceGranted < #7/1/2002# And IsNull(Me.LicenceSurrendered)) _
Or (Me.LicenceGranted < #7/1/2002# _
And Me.LicenceSurrendered >= #7/1/2001#) Then
Me.chk2001_02.Value = True
Else
Me.chk2001_02.Value = False
End If

' ----------end code

Regards
Dylan

Since the control's Value property is the default, you do not need to
refer to it.
Me.chk2001_02 = True
 
Back
Top