By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,968 Members | 1,661 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,968 IT Pros & Developers. It's quick & easy.

VBA If statements - need a bit of help

P: n/a
Before executing some code I want to check for some null values so I
have this code...

If IsNull(cboCarton) Or cboCarton = "" Then
MsgBox "Specify Carton Type", vbCritical, "Required Data"
Me.cboCarton.SetFocus
Exit Sub
End If

But what if I want to check if

CboCarton = 0 then do some action,

but if cboCarton = 0 and txtCarton = >0 then do some action.;.. I cant
figure out how to make two criteria checked before proceeding.

Thanks,

Dave

Sep 29 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
You mean like this?

If cboCarton = 0 Then
Do Whatever
If txtCarton >= 0 then
Do Whatever Here
End If
End If

Hope that helps!
st********@hotmail.com wrote:
Before executing some code I want to check for some null values so I
have this code...

If IsNull(cboCarton) Or cboCarton = "" Then
MsgBox "Specify Carton Type", vbCritical, "Required Data"
Me.cboCarton.SetFocus
Exit Sub
End If

But what if I want to check if

CboCarton = 0 then do some action,

but if cboCarton = 0 and txtCarton = >0 then do some action.;.. I cant
figure out how to make two criteria checked before proceeding.

Thanks,

Dave
Sep 29 '06 #2

P: n/a
I don't think so.. Im trying to make sure that that if

CboCarton=0 then
exit sub,

or

If cboCarton=0 but txtCarton is not null or txtcarton=>0 then
process this line
else
exit sub...

Let me know if this makes more sense..

Thanks,

Dave


Jeff L wrote:
You mean like this?

If cboCarton = 0 Then
Do Whatever
If txtCarton >= 0 then
Do Whatever Here
End If
End If

Hope that helps!
st********@hotmail.com wrote:
Before executing some code I want to check for some null values so I
have this code...

If IsNull(cboCarton) Or cboCarton = "" Then
MsgBox "Specify Carton Type", vbCritical, "Required Data"
Me.cboCarton.SetFocus
Exit Sub
End If

But what if I want to check if

CboCarton = 0 then do some action,

but if cboCarton = 0 and txtCarton = >0 then do some action.;.. I cant
figure out how to make two criteria checked before proceeding.

Thanks,

Dave
Sep 29 '06 #3

P: n/a
On 29 Sep 2006 12:25:30 -0700, st********@hotmail.com wrote:
>I don't think so.. Im trying to make sure that that if

CboCarton=0 then
exit sub,

or

If cboCarton=0 but txtCarton is not null or txtcarton=>0 then
process this line
else
exit sub...

Let me know if this makes more sense..

Thanks,

Dave


Jeff L wrote:
>You mean like this?

If cboCarton = 0 Then
Do Whatever
If txtCarton >= 0 then
Do Whatever Here
End If
End If

Hope that helps!
st********@hotmail.com wrote:
Before executing some code I want to check for some null values so I
have this code...

If IsNull(cboCarton) Or cboCarton = "" Then
MsgBox "Specify Carton Type", vbCritical, "Required Data"
Me.cboCarton.SetFocus
Exit Sub
End If

But what if I want to check if

CboCarton = 0 then do some action,

but if cboCarton = 0 and txtCarton = >0 then do some action.;.. I cant
figure out how to make two criteria checked before proceeding.

Thanks,

Dave
It sounds to me as though what you need is ElseIF.

If cboCarton = 0 AND txtCarton =0 Then
do some stuff
ElseIF cboCarton = 0 Then
so some other stuff
End If

The only way that the second part would get executed is if txtCarton
had a value less than 0.

-=-=-=-=-=-=-=-=-=-=-=-=
Randy Harris
tech at promail dot com
Sep 29 '06 #4

P: n/a
I use:

If Len(Trim$(##FIELD## & vbNullString)) = 0 then
'it's empty
Else
'it's not
End if

Jon

Sep 29 '06 #5

P: n/a
Randy's use of the the elseif is a good solution.
You can also simplify your statements using NZ.
Nz is 'null to zero.' It will return param2 if param1 is null.
Rather than If isnull(cbo) or cbo="" then...
you can say if nz(cbo,"")="" then...

Also if you need to complicate your if statements, you can use
parenthesis set your order of operations. As a hypothetical example:
If (cbo="" and txt="") or (cbo>0 and lst<0) then...

Hth
Pachydermitis

Randy Harris wrote:
On 29 Sep 2006 12:25:30 -0700, st********@hotmail.com wrote:
I don't think so.. Im trying to make sure that that if

CboCarton=0 then
exit sub,

or

If cboCarton=0 but txtCarton is not null or txtcarton=>0 then
process this line
else
exit sub...

Let me know if this makes more sense..

Thanks,

Dave


Jeff L wrote:
You mean like this?

If cboCarton = 0 Then
Do Whatever
If txtCarton >= 0 then
Do Whatever Here
End If
End If

Hope that helps!
st********@hotmail.com wrote:
Before executing some code I want to check for some null values so I
have this code...

If IsNull(cboCarton) Or cboCarton = "" Then
MsgBox "Specify Carton Type", vbCritical, "Required Data"
Me.cboCarton.SetFocus
Exit Sub
End If

But what if I want to check if

CboCarton = 0 then do some action,

but if cboCarton = 0 and txtCarton = >0 then do some action.;.. I cant
figure out how to make two criteria checked before proceeding.

Thanks,

Dave

It sounds to me as though what you need is ElseIF.

If cboCarton = 0 AND txtCarton =0 Then
do some stuff
ElseIF cboCarton = 0 Then
so some other stuff
End If

The only way that the second part would get executed is if txtCarton
had a value less than 0.

-=-=-=-=-=-=-=-=-=-=-=-=
Randy Harris
tech at promail dot com
Sep 30 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.