If Statement for sub-form needed!

D

Dave Elliott

Syntax below is wrong, I know, but this is what I need.
If the sub-form TimeCardPaymentSub control Payment Is NotNull and on the
same sub-form the control Balance IsNull
then messagebox.

If (sub-form) [TimeCardPaymentSub] (Control) [Payment] IsNotNull and
[Balance] IsNull Then
MsgBox "Why is there more material on this job?"
End If
 
M

M Skabialka

Here's a snippet from my code:

If Not IsNull([Forms]![frmMainform]![frmMainform
Subform].[Form]![AccountNumber]) Then

I haven't used () in referrring to subforms or controls - so not sure if
this is OK...
 
S

Sandra Daigle

Dave,

Is this code in the class module of the main form? If so here's what you
need:

If not isnull(me.TimeCardPaymentSub.form.Payment) and _
isnull(me.TimeCardPaymentSub.form.Balance) Then
MsgBox "Why is there more material on this job?"
End If

This could be shortened a bit using the With..End With construct:

With me.TimeCardPaymentSub.form
if not isnull(.Payment) and _
isnull(.Balance) Then
MsgBox "Why is there more material on this job?"
End If
End with
 
D

Dave Elliott

If Not
IsNull([Forms]![TimeCards]![TimeCardPaymentSub].[Form]![AccountNumber]) Then

MsgBox "Why is there more material on this job?"
End If

Need to add to this and if balance equals zero Then MsgBox
Balance is on the same sub-form TimeCardPaymentSub


M Skabialka said:
Here's a snippet from my code:

If Not IsNull([Forms]![frmMainform]![frmMainform
Subform].[Form]![AccountNumber]) Then

I haven't used () in referrring to subforms or controls - so not sure if
this is OK...



Dave Elliott said:
Syntax below is wrong, I know, but this is what I need.
If the sub-form TimeCardPaymentSub control Payment Is NotNull and on the
same sub-form the control Balance IsNull
then messagebox.

If (sub-form) [TimeCardPaymentSub] (Control) [Payment] IsNotNull and
[Balance] IsNull Then
MsgBox "Why is there more material on this job?"
End If
 
S

Sandra Daigle

Hi Dave,

In that case you can simply refer to the controls via the "Me" keyword since
'Me' in this case is a reference to form object.

If not isnull(me..Payment) and _
isnull(me..Balance) Then
MsgBox "Why is there more material on this job?"
End If

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


Dave said:
Actually the code is in the exit event of a control on the sub-form .

Sandra Daigle said:
Dave,

Is this code in the class module of the main form? If so here's what
you need:

If not isnull(me.TimeCardPaymentSub.form.Payment) and _
isnull(me.TimeCardPaymentSub.form.Balance) Then
MsgBox "Why is there more material on this job?"
End If

This could be shortened a bit using the With..End With construct:

With me.TimeCardPaymentSub.form
if not isnull(.Payment) and _
isnull(.Balance) Then
MsgBox "Why is there more material on this job?"
End If
End with


--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

Dave said:
Syntax below is wrong, I know, but this is what I need.
If the sub-form TimeCardPaymentSub control Payment Is NotNull and
on the same sub-form the control Balance IsNull
then messagebox.

If (sub-form) [TimeCardPaymentSub] (Control) [Payment] IsNotNull and
[Balance] IsNull Then
MsgBox "Why is there more material on this job?"
End If
 
D

Dave Elliott

Is this true even if it refers to a sub-form?
This code is being triggered form a sub-form checking on another sub-form on
my main form!

Sandra Daigle said:
Hi Dave,

In that case you can simply refer to the controls via the "Me" keyword
since 'Me' in this case is a reference to form object.

If not isnull(me..Payment) and _
isnull(me..Balance) Then
MsgBox "Why is there more material on this job?"
End If

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


Dave said:
Actually the code is in the exit event of a control on the sub-form .

Sandra Daigle said:
Dave,

Is this code in the class module of the main form? If so here's what
you need:

If not isnull(me.TimeCardPaymentSub.form.Payment) and _
isnull(me.TimeCardPaymentSub.form.Balance) Then
MsgBox "Why is there more material on this job?"
End If

This could be shortened a bit using the With..End With construct:

With me.TimeCardPaymentSub.form
if not isnull(.Payment) and _
isnull(.Balance) Then
MsgBox "Why is there more material on this job?"
End If
End with


--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

Dave Elliott wrote:
Syntax below is wrong, I know, but this is what I need.
If the sub-form TimeCardPaymentSub control Payment Is NotNull and
on the same sub-form the control Balance IsNull
then messagebox.

If (sub-form) [TimeCardPaymentSub] (Control) [Payment] IsNotNull and
[Balance] IsNull Then
MsgBox "Why is there more material on this job?"
End If
 
M

M Skabialka

If you are on any form you can refer to a control on that form using
Me.fieldname but you must use the entire name when refering to another form
or subform.

Controls on this form:
[Me]![fieldname] or even fieldname in some cases (watch out for keywords)

Controls on the other subform:
[Forms]![mymainform]![mysubform1].[Form]![fieldname]

Controls on the main form:
[Forms]![mymainform]![fieldname]

Dave Elliott said:
Is this true even if it refers to a sub-form?
This code is being triggered form a sub-form checking on another sub-form
on my main form!

Sandra Daigle said:
Hi Dave,

In that case you can simply refer to the controls via the "Me" keyword
since 'Me' in this case is a reference to form object.

If not isnull(me..Payment) and _
isnull(me..Balance) Then
MsgBox "Why is there more material on this job?"
End If

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


Dave said:
Actually the code is in the exit event of a control on the sub-form .

Dave,

Is this code in the class module of the main form? If so here's what
you need:

If not isnull(me.TimeCardPaymentSub.form.Payment) and _
isnull(me.TimeCardPaymentSub.form.Balance) Then
MsgBox "Why is there more material on this job?"
End If

This could be shortened a bit using the With..End With construct:

With me.TimeCardPaymentSub.form
if not isnull(.Payment) and _
isnull(.Balance) Then
MsgBox "Why is there more material on this job?"
End If
End with


--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

Dave Elliott wrote:
Syntax below is wrong, I know, but this is what I need.
If the sub-form TimeCardPaymentSub control Payment Is NotNull and
on the same sub-form the control Balance IsNull
then messagebox.

If (sub-form) [TimeCardPaymentSub] (Control) [Payment] IsNotNull and
[Balance] IsNull Then
MsgBox "Why is there more material on this job?"
End If
 
S

Sandra Daigle

Oh! That definately makes a difference. In that case it's back to something
similar to the earlier syntax. For simplicity lets say the main form is
named frmMain and you have subform controls sfrmForm1 and sfrmForm2. Both
are directly on the main form (ie neither are sub-sub forms). Lets say the
controls are text1 and text2 and they are on sfrmForm2. The following code
will work from sfrmForm1:

if not isnull(forms!frmMain.sfrmForm2.form.Text1) and _
isnull(forms!frmMain.sfrmForm2.form.Text2) then
MsgBox "Why is there more material on this job?"
End If

From the class module of sfrmForm1 me.parent is a reference to the form
object of the parent form (frmMain). Therefore the above could be written
this way:

if not isnull(me.parent.sfrmForm2.Text1) and _
isnull(me.parent.sfrmForm2.Text2) then
MsgBox "Why is there more material on this job?"
End If

Keep in mind that "sfrmForm1" and "sfrmForm2" are the names of the subform
controls. To find the name of the subform control click once on the subform
control to select it then check the 'Name' property under the 'Other' tab in
the property sheet.

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


Dave said:
Is this true even if it refers to a sub-form?
This code is being triggered form a sub-form checking on another
sub-form on my main form!

Sandra Daigle said:
Hi Dave,

In that case you can simply refer to the controls via the "Me"
keyword since 'Me' in this case is a reference to form object.

If not isnull(me..Payment) and _
isnull(me..Balance) Then
MsgBox "Why is there more material on this job?"
End If

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


Dave said:
Actually the code is in the exit event of a control on the sub-form
Dave,

Is this code in the class module of the main form? If so here's
what you need:

If not isnull(me.TimeCardPaymentSub.form.Payment) and _
isnull(me.TimeCardPaymentSub.form.Balance) Then
MsgBox "Why is there more material on this job?"
End If

This could be shortened a bit using the With..End With construct:

With me.TimeCardPaymentSub.form
if not isnull(.Payment) and _
isnull(.Balance) Then
MsgBox "Why is there more material on this job?"
End If
End with


--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this
newsgroup. Dave Elliott wrote:
Syntax below is wrong, I know, but this is what I need.
If the sub-form TimeCardPaymentSub control Payment Is NotNull and
on the same sub-form the control Balance IsNull
then messagebox.

If (sub-form) [TimeCardPaymentSub] (Control) [Payment] IsNotNull
and [Balance] IsNull Then
MsgBox "Why is there more material on this job?"
End If
 
D

Dave Elliott

This is close to what I want, but what is wrong with my If statement syntax?

If NotIsNull(Forms!TimeCards.TimeCardPaymentSub.Payment) And
IsNull(Forms!TimeCards.TimeCardPaymentSub.Balance) Then
MsgBox "Why is there more material on this job?"
End If
 
D

Dave Elliott

Further explanation:
if there is a value or number in the (payment) control on the sub-form and
if the control (balance) equals zero, then
message box
 
S

Sandra Daigle

In the following, "Not" is a separate keyword from "IsNull":

If Not IsNull(Forms!TimeCards.TimeCardPaymentSub.Payment) And
IsNull(Forms!timeCards.TimeCardPaymentSub.Balance) Then
MsgBox "Why is there more material on this job?"
End If

However the above also tests whether "Balance" is Null. To test whether it
is zero the condition would be:

If Not IsNull(Forms!TimeCards.TimeCardPaymentSub.Payment) And
Forms!timeCards.TimeCardPaymentSub.Balance=0 Then
MsgBox "Why is there more material on this job?"
End If
 

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