Why is this Load Event code not working? Please help.

B

Bob Quintal

I am trying to disable some controls on a form when it opens using
this Load event but it is not working. Is there something I am
doing wrong. I even tried using .Visible and that didn't work
either. Can someone please tell me what I am doing wrong. Thank
you.

You are trying to compare field values to null. Null does not =
Null, What you want to do is test to see if the fields are null
using the isnull function.

If isNull(Me.txtVendor.Value) Then
If isNull(Me.txtReviewer.Value) Then
etc.
Private Sub Form_Load()
If Me.txtVendor.Value = Null Then
Me.txtVendor.Enabled = False
End If
If Me.txtReviewer.Value = Null Then
Me.txtReviewer.Enabled = False
End If
If Me.txtBeginDateRange.Value = Null Then
Me.txtBeginDateRange.Enabled = False
'Me.lblSDR.Enabled = False
End If
If Me.txtEndDateRange.Value = Null Then
Me.txtEndDateRange.Enabled = False
'Me.lblEDR.Enabled = False
End If
If Me.txtSingleDate.Value = Null Then
Me.txtSingleDate.Enabled = False
'me.lblSingleDate.Enabled = False
End If
End Sub
 
A

Ayo

I am trying to disable some controls on a form when it opens using this Load
event but it is not working. Is there something I am doing wrong. I even
tried using .Visible and that didn't work either. Can someone please tell me
what I am doing wrong. Thank you.

Private Sub Form_Load()
If Me.txtVendor.Value = Null Then
Me.txtVendor.Enabled = False
End If
If Me.txtReviewer.Value = Null Then
Me.txtReviewer.Enabled = False
End If
If Me.txtBeginDateRange.Value = Null Then
Me.txtBeginDateRange.Enabled = False
'Me.lblSDR.Enabled = False
End If
If Me.txtEndDateRange.Value = Null Then
Me.txtEndDateRange.Enabled = False
'Me.lblEDR.Enabled = False
End If
If Me.txtSingleDate.Value = Null Then
Me.txtSingleDate.Enabled = False
'me.lblSingleDate.Enabled = False
End If
End Sub
 
D

Dirk Goldgar

Ayo said:
I am trying to disable some controls on a form when it opens using this
Load
event but it is not working. Is there something I am doing wrong. I even
tried using .Visible and that didn't work either. Can someone please tell
me
what I am doing wrong. Thank you.

Private Sub Form_Load()
If Me.txtVendor.Value = Null Then
Me.txtVendor.Enabled = False
End If
If Me.txtReviewer.Value = Null Then
Me.txtReviewer.Enabled = False
End If
If Me.txtBeginDateRange.Value = Null Then
Me.txtBeginDateRange.Enabled = False
'Me.lblSDR.Enabled = False
End If
If Me.txtEndDateRange.Value = Null Then
Me.txtEndDateRange.Enabled = False
'Me.lblEDR.Enabled = False
End If
If Me.txtSingleDate.Value = Null Then
Me.txtSingleDate.Enabled = False
'me.lblSingleDate.Enabled = False
End If
End Sub

Nothing is ever *equal* to Null. To test for Null in VBA code, use code
along the lines of:

If IsNull(Me.txtVendor.Value) Then
 
A

Ayo

Thanks. I knew that, I was getting desperate and I was just trying everything
I can.
The code is not working still. If the value is null then .enabled=False but
even when there is value in the txtbox it is still showing as disabled. That
is my problem. ANy ideas? Thanks.
Ayo

If IsNull(Me.txtVendor.Value) Then
Me.txtVendor.Enabled = False
End If
if IsNull(Me.txtReviewer.Value) Then
Me.txtReviewer.Enabled = False
End If
If IsNull(Me.txtBeginDateRange.Value) Then
Me.txtBeginDateRange.Enabled = False
'Me.lblSDR.Enabled = False
End If
If IsNull(Me.txtEndDateRange.Value) Then
Me.txtEndDateRange.Enabled = False
'Me.lblEDR.Enabled = False
End If
If IsNull(Me.txtSingleDate.Value) Then
Me.txtSingleDate.Enabled = False
'me.lblSingleDate.Enabled = False
End If
 
A

Ayo

Thanks. I knew that, I was getting desperate and I was just trying everything
I can.
The code is not working still. If the value is null then .enabled=False but
even when there is value in the txtbox it is still showing as disabled. That
is my problem. ANy ideas? Thanks.
Ayo

If IsNull(Me.txtVendor.Value) Then
Me.txtVendor.Enabled = False
End If
if IsNull(Me.txtReviewer.Value) Then
Me.txtReviewer.Enabled = False
End If
If IsNull(Me.txtBeginDateRange.Value) Then
Me.txtBeginDateRange.Enabled = False
'Me.lblSDR.Enabled = False
End If
If IsNull(Me.txtEndDateRange.Value) Then
Me.txtEndDateRange.Enabled = False
'Me.lblEDR.Enabled = False
End If
If IsNull(Me.txtSingleDate.Value) Then
Me.txtSingleDate.Enabled = False
'me.lblSingleDate.Enabled = False
End If
 
B

boblarson

From what I'm seeing is that you never, ever tell it what to do if it ISN'T
null. You might want to check your settings to see if you have actually set
the controls to be enabled in the properties OR modify the code as follows:

If IsNull(Me.txtVendor.Value) Then
Me.txtVendor.Enabled = False
Else
Me.txtVendor.Enabled = True
End If

if IsNull(Me.txtReviewer.Value) Then
Me.txtReviewer.Enabled = False
Else
Me.txtReviewer.Enabled = True
End If

If IsNull(Me.txtBeginDateRange.Value) Then
Me.txtBeginDateRange.Enabled = False
Me.lblSDR.Enabled = False
Else
Me.txtBeginDateRange.Enabled = True
Me.lblSDR.Enabled = True
End If

If IsNull(Me.txtEndDateRange.Value) Then
Me.txtEndDateRange.Enabled = False
Me.lblEDR.Enabled = False
Else
Me.txtEndDateRange.Enabled = True
Me.lblEDR.Enabled = True
End If

If IsNull(Me.txtSingleDate.Value) Then
Me.txtSingleDate.Enabled = False
Me.lblSingleDate.Enabled = False
Else
Me.txtSingleDate.Enabled = True
Me.lblSingleDate.Enabled = True
End If


--
Bob Larson
Access World Forums Super Moderator
Utter Access VIP
Tutorials at http://www.btabdevelopment.com
__________________________________
If my post was helpful to you, please rate the post.
 
D

Douglas J. Steele

Are you talking about a continuous form, or a form in datasheet view?

If so, it's working as designed: Access sets the control to disabled for
every instance, not just for the ones that are Null. You can try putting the
code into the Current event (after changing it so that it enables the
controls when they're not Null). In that way, every instance of txtVendor
will be disabled if the current one is Null, but since you can only deal
with the current instance, that shouldn't matter.
 

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