Code on Current Event of Sub-Form

D

Dave Elliott

This is my code which fires on the current event of a sub-form on my main
form.
Nothing Happens????
SentVia is a TextBox and LblPrtInv is a label
What am I doing wrong?

If IsNull(Forms!FTimeBillingSub!SentVia) Then
LblPrtInv.Visible = False
End If
 
D

DebbieG

Is LblPrtInv on the subform? If so you need to tell it that.

If IsNull(Forms!FTimeBillingSub!SentVia) Then
Forms!FTimeBillingSub!LblPrtInv.Visible = False
Else
Forms!FTimeBillingSub!LblPrtInv.Visible = True
End If


| This is my code which fires on the current event of a sub-form on my main
| form.
| Nothing Happens????
| SentVia is a TextBox and LblPrtInv is a label
| What am I doing wrong?
|
| If IsNull(Forms!FTimeBillingSub!SentVia) Then
| LblPrtInv.Visible = False
| End If
 
E

elwin

I'm assuming that 'lblPrtInv' is on the subform, so you need to specify which
object it belongs to

Me!lblPrtInv.Visible = False


but also, to expand on DebbieG's answer, if you want to refer to a control
on the main form from a subform use the parent object.

Me.Parent.Controls("lblPrtInv").Visible = False


If you want to refer to a control on the subform from the main form, include
the form object of the subform control.

Me!sfrmControlName.Form!lblPrtInv.Visible = False


A period preceeds property and collection names. An exclamation point
preceeds user assigned control and object names.
 
J

JP

I'm assuming that SentVia and LblPrtInv are both controls on the subform.
In that case, your references to the fields are incorrect in the IF
statement.

1. Since FTimeBillingSub is a subform, Access won't find it with this
reference since it's not opened as a form itself but rather appears as a
control on a form (a subform control, but still a control and not a form).
Normally, you have to use a reference that refers to the main form and then
the subform control of the main form. www.mvps.org/access has a very good
writeup on how to refer to one form from another, how to refer to subforms,
etc.

In this case, since you're trying to do this in the current event of the
subform itself, you can just use the Me. reference:

If IsNull(Me.SentVia) Then

2. You have to use a form-based reference to the label itself. Again, you
can use the Me. since you're trying to do this from within an event on the
subform

Me.LblPrtInv.Visible = False

The above two items are probably causing your problem

You might want to also check and make sure that the value of SentVia really
is null, and not just a zero length string (or for that matter, a non-zero
length blank string).

By the way, if you have this code, what are you going to do on new records
since the value of SentVia will be null? Your label will never show on new
records for entry of the field. Alternatively, if you have a default value
for SentVia, then you'll never have a null in there which means the label
will never be hidden.
 
D

Dave Elliott

LblPrtInv is in the Form Header
Yes, it is on the sub-form
Tried it, it did nothing.
 
D

Dave Elliott

Since th default vale of SentVia is visible and it is a text value, then the
only criteria I should have to use is
Visible = False
Both controls are on my sub-form, just the Label LblPrtInv is on the Form
Header of the form.
 
J

JP

Dave,

Sorry, you lost me on your reply.

If the table field underlying SentVia has a default, then Me.SentVia in the
subform will never be null and your label will never be made invisible.

But what did you mean that the only criteria you should have to use is
Visible = False?
 
D

Dave Elliott

Even Tried
LblPrtInv.Visible = IsNotNullForms!FTimeBillingSub!(Me.SentViaID)

This did not work either; Note: SentVia is name of control, Control Source
is SentViaID
 
D

Dave Elliott

THIS THE CODE THAT WORKED:
Thanks for your help!!!


If Not IsNull(Me.SentViaID) Then
LblPrtInv.Visible = True
End If
If IsNull(Me.SentViaID) Then
LblPrtInv.Visible = False
End If
 
J

JP

Dave,

Re-read my first reply.

You do NOT want to be using the reference Forms!FTimeBillingSub anywhere in
this code.

If isnull(me.sentvia) then
me.lblPrtInv.visible = false
endif

The other question is the value of SentVia (or SentViaID) itself. If
there's a default, then the value of SentViaID (and the SentVia textbox)
will NEVER be null, which means that your label will always be visible.
 

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