473,387 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

VBA If statements - need a bit of help

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
5 4556
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
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
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
I use:

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

Jon

Sep 29 '06 #5
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Nipon | last post by:
Hi, I am using MS SQL Server 7.0 SP2 in Windows 2000 server SP4. I have one-to-many tables (TABLE_HEAD and TABLE_DETAILS)which I am going to update by using a stored procedure with UPDATE...
1
by: jan | last post by:
Hello, I am new to this list and would appreciate some help with Access 2000 and Access 2003. I need to export our access database table statements by access database to place into our database...
35
by: David Cleaver | last post by:
Hello all, I was wondering if there were some sort of limitations on the "if" statement? I'm writing a program which needs to check a bunch of conditions all at the same time (basically). And...
3
by: Amy | last post by:
Hi, I have 6 If Then Else statements I was supposed to write. I did so but I know that they have to be wrong because they all look the same. Could someone take a look at them and point me in the...
2
by: saran | last post by:
I am having a problem with MySQL consuming a lot of memory and eventually throwing an Out of Memory error and restarting itself. The symptoms are that swap usage continues to rise until some...
9
by: colin.mcnulty | last post by:
Hi, I'm a SQL Server DBA, but I guess that won't buy me any friends round here huh? ;-) I've been asked to look at the SQL that's being executed on a DB2 database from a web app, specifically...
5
by: Eric_Dexter | last post by:
I was trying to add this to my project but I must be missing some includes or there is a serius error somewhere Anthra Norell wrote:
14
by: Ben | last post by:
I don't know whether anyone can help, but I have an odd problem. I have a PSP (Spyce) script that makes many calls to populate a database. They all work without any problem except for one...
7
by: =?Utf-8?B?QVRT?= | last post by:
HOWTO Run multiple SQL statements from ASP/ADO to an Oracle 10g. Please help, I'm trying to write an ASP page to use ADO to run a long query against an Oracle 10g database, to create tables,...
0
by: Ohad Frand | last post by:
Hi Thanks a lot for your reply I think the main uses for it is to study the language and to see that I didn't miss anything else or that something is changed from one version to another. The...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.