473,416 Members | 1,572 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,416 software developers and data experts.

Using IFF statement in Access

Bob


Currently I am using this statement to translate 3 fields in my db
thru Visual Basic. I import the data from one table to another then
call the IFF statements and the NewDate to translate the fields. Can
this be done in an Access db? I am trying to learn how to do these
things in Access vs Visual

Dim strIIF As String
Dim sstrIIF As String

Dim strNewDate As Date
Dim strDate As String

strDate = "20030207153015"

strDate = Mid$(strDate, 5, 2) & "/" & Mid$(strDate, 7, 2) & "/" &
Left$(strDate, 4)

strNewDate = DateValue(strDate)

strIIF = "IIF(calShipment.m_serviceType=2,'Next Day Air',
IIF(calShipment.m_serviceType=19,'Next Day Air
AM',IIF(calShipment.m_serviceType=13,'Next Day Air
Saver',IIF(calShipment.m_serviceType=59,'2nd Day Air
AM',IIF(calShipment.m_serviceType=3,'2nd Day
Air',IIF(calShipment.m_serviceType=12,'3 Day
Select',IIF(calShipment.m_serviceType=17,'Worldwid e
Expedited',IIF(calShipment.m_serviceType=8,'Worldw ide
Express',IIF(calShipment.m_serviceType=7,'Standard ',IIF(calShipment.m_serviceType=4,'Ground')))))))) ))"

sstrIIF = "IIF(calPackage.m_isPkgVoid=0,'Sent',
IIF(calPackage.m_isPkgVoid=1,'Voided'))"

Thanks
Bob
Nov 12 '05 #1
7 35652
What you've shown is how you build the IIF statements, not how you use them,
and I don't understand what you mean by "call the IFF statements and the
NewDate to translate the fields".

Fact is, all that you've shown can be done in VBA (it is, after all, not
only the language of Access and other office applications, but the core
language of classic VB, as well). So chances are, if you wish, you can
likely do it exactly the same.

However, if you'd clarify just what it is that you have and what you want to
accomplish, rather than code details of only part of the way you have been
doing it, someone here might be able to suggest a simpler, easier way to do
what you want. For example, with the long, nested IIF, and the other for
that matter, are you creating a new Field value, or are you updating one
that already exists?

I would imagine that running an update query can accomplish what you need to
do, and if you've been reading the table record by record with either ADO or
DAO, and updating each, then that almost certainly will be both easier and
more efficient. In fact, an Access/Jet query can call a user-defined Access
function in the Access application that issues it, and that might be a good
deal easier to read than a nested IIF.

Larry Linson
Microsoft Access MVP

"Bob" <rt********@comcast.net> wrote in message
news:93********************************@4ax.com...


Currently I am using this statement to translate 3 fields in my db
thru Visual Basic. I import the data from one table to another then
call the IFF statements and the NewDate to translate the fields. Can
this be done in an Access db? I am trying to learn how to do these
things in Access vs Visual

Dim strIIF As String
Dim sstrIIF As String

Dim strNewDate As Date
Dim strDate As String

strDate = "20030207153015"

strDate = Mid$(strDate, 5, 2) & "/" & Mid$(strDate, 7, 2) & "/" &
Left$(strDate, 4)

strNewDate = DateValue(strDate)

strIIF = "IIF(calShipment.m_serviceType=2,'Next Day Air',
IIF(calShipment.m_serviceType=19,'Next Day Air
AM',IIF(calShipment.m_serviceType=13,'Next Day Air
Saver',IIF(calShipment.m_serviceType=59,'2nd Day Air
AM',IIF(calShipment.m_serviceType=3,'2nd Day
Air',IIF(calShipment.m_serviceType=12,'3 Day
Select',IIF(calShipment.m_serviceType=17,'Worldwid e
Expedited',IIF(calShipment.m_serviceType=8,'Worldw ide
Express',IIF(calShipment.m_serviceType=7,'Standard ',IIF(calShipment.m_servic
eType=4,'Ground'))))))))))"
sstrIIF = "IIF(calPackage.m_isPkgVoid=0,'Sent',
IIF(calPackage.m_isPkgVoid=1,'Voided'))"

Thanks
Bob

Nov 12 '05 #2
Bob
I am still trying to learn how to use Access for other than storing
the data

What I am doing in Visual is

I have one db that I am using a query to pull data from 3 tables based
on the primary and foreign keys. In the db 2 of the fields in the
calShipment table and 1 in the calPackage table are the ones I am
addressing.

calShipment m_shipDateTime field stores the date/time as a string
20030923102015 or yyyymmddhhmmss
calShipment m_serviceType field stores the data as a number
2 = Next Day Air and so forth
calPackage m_isPkgVoid field stores the data as a number
1 = Voided and 0 = Sent

In my sql statement to pull the data into a temp table and use the
date statement, and the strIFF and sstrIIF to translate the other
fields

sql = "SELECT calPkgAgent.Sm_customerId, calPkgAgent.Sm_businessName,
calPkgAgent.m_Attention, calPkgAgent.m_StreetAddress,
calPkgAgent.m_RoomFloor, calPkgAgent.m_Department, calPkgAgent.m_City,
calPkgAgent.m_StateProv, calPkgAgent.m_PostalCode, " & strIIF & ",
DateValue(Mid$(calShipment.m_shipDateTime, 5, 2) & '/' &Mid$(
calShipment.m_shipDateTime,7, 2) & '/' & Left$(
calShipment.m_shipDateTime,4)) As NewDate, (calPackage.m_pkgCost/100)
as Expr1, (calPackage.m_weight/10) as Expr2, calPackage.Sm_trackingNo,
calPackage.Sm_referenceText0, calPackage.Sm_referenceText1,
calShipment.m_shipDataSet, " & sstrIIF & " INTO Table1 IN
'C:\DataBackUp\Temp.mdb' FROM calPkgAgent, calPackage, calShipment
WHERE calPkgAgent.m_primaryKey = calShipment.m_foreignKey00 AND
calPackage.m_foreignKey = calShipment.m_primaryKey"

the NewDate gives me 09/23/2003
the strIFF gives me the correct service
the sstrIFF gives me the correct Void or Sent

I hope you can understand what I am trying to do. I am very new to
access and most of the books don't really show me things of thios
nature.

Thanks
Bob
On Wed, 24 Sep 2003 01:28:48 GMT, "Larry Linson"
<bo*****@localhost.net> wrote:
What you've shown is how you build the IIF statements, not how you use them,
and I don't understand what you mean by "call the IFF statements and the
NewDate to translate the fields".

Fact is, all that you've shown can be done in VBA (it is, after all, not
only the language of Access and other office applications, but the core
language of classic VB, as well). So chances are, if you wish, you can
likely do it exactly the same.

However, if you'd clarify just what it is that you have and what you want to
accomplish, rather than code details of only part of the way you have been
doing it, someone here might be able to suggest a simpler, easier way to do
what you want. For example, with the long, nested IIF, and the other for
that matter, are you creating a new Field value, or are you updating one
that already exists?

I would imagine that running an update query can accomplish what you need to
do, and if you've been reading the table record by record with either ADO or
DAO, and updating each, then that almost certainly will be both easier and
more efficient. In fact, an Access/Jet query can call a user-defined Access
function in the Access application that issues it, and that might be a good
deal easier to read than a nested IIF.

Larry Linson
Microsoft Access MVP

"Bob" <rt********@comcast.net> wrote in message
news:93********************************@4ax.com.. .


Currently I am using this statement to translate 3 fields in my db
thru Visual Basic. I import the data from one table to another then
call the IFF statements and the NewDate to translate the fields. Can
this be done in an Access db? I am trying to learn how to do these
things in Access vs Visual

Dim strIIF As String
Dim sstrIIF As String

Dim strNewDate As Date
Dim strDate As String

strDate = "20030207153015"

strDate = Mid$(strDate, 5, 2) & "/" & Mid$(strDate, 7, 2) & "/" &
Left$(strDate, 4)

strNewDate = DateValue(strDate)

strIIF = "IIF(calShipment.m_serviceType=2,'Next Day Air',
IIF(calShipment.m_serviceType=19,'Next Day Air
AM',IIF(calShipment.m_serviceType=13,'Next Day Air
Saver',IIF(calShipment.m_serviceType=59,'2nd Day Air
AM',IIF(calShipment.m_serviceType=3,'2nd Day
Air',IIF(calShipment.m_serviceType=12,'3 Day
Select',IIF(calShipment.m_serviceType=17,'Worldwid e
Expedited',IIF(calShipment.m_serviceType=8,'Worldw ide

Express',IIF(calShipment.m_serviceType=7,'Standar d',IIF(calShipment.m_servic
eType=4,'Ground'))))))))))"

sstrIIF = "IIF(calPackage.m_isPkgVoid=0,'Sent',
IIF(calPackage.m_isPkgVoid=1,'Voided'))"

Thanks
Bob


Nov 12 '05 #3
I hope that you haven't felt it necessary or desirable to start from scratch
writing SQL in Access. Access gives you the Query Builder which is an
excellent, unpaid SQL-writing Assistant. I'll just assume that you're using
the SQL as a communication vehicle, but that you saved yourself a great deal
of time and effort by using File | Get External Data to link the tables in
the other database. If not, take a look at it, and I think you'll soon
"learn to love it" -- that is, unless you are an SQL hobbyist. <G>

I believe I'd create myself a local table with the numeric values and text
for the service type, and join those to the appropriate fields in
calShipment and calPackage in a MakeTable or Update Query, and do the same
for m_isPkgVoid field. Then again, I might just leave those fields numeric,
and do the join only when I needed the text values for display in a Form or
a Report.

(For a MakeTable or Update Query, create the Query as a Select, and in
Design View in the Query Builder, on the menu Query | Make Table or Update.
However, see below: you may not need to create a temporary table.)

Your expression for manipulating the date looks good to me, but this, too,
can be accomplished without any temporary or intermediate table, in the
Query that you use as RecordSource for the Form or Report where the data is
viewed and/or used.

On the other hand, if the tables from which you are extracting the
information are transitory in nature, and may not be around when you need
the information, bringing that information in to a local table (not
necessarily temporary) would obviously be a good idea. If you maintain past
data in your local table(s), you may be able to get "extra value" by
analyzing it at some future time.

A Service Type table would consist of two fields (or more, if you think you
may need additional description or information): the service type number,
and service type name. You'd join it to the calShipment.m_serviceType field
on service type number, but pull the service type name down into the Query
Builder Grid. The text for m_isPkgVoid could be handled the same way, or
created as a Calculated Field in the Query using the IIf statement you
cited.

If I haven't been clear enough, follow up and I'll try to clarify.

Larry Linson
Microsoft Access MVP

Nov 12 '05 #4
Have you tried a Select Case statement:

Dim intShipmentType as Integer
Dim intPackageVoid as Integer
intShipmentType = calShipment.m_serviceType
intPackageVoid = calPackage.m_isPkgVoid

Selct Case intShipmentType
Case 2
strIIF = "Next Day Air"
Case 19
strIIF = "Next Day Air AM"
Case Else
strIIF = "whatever"
End Select

Selct Case intPackageVoid
Case 0
sstrIIF = "Sent"
Case 1
sstrIIF = "Voided"
Enb Select

Reggie

"Half this game is 90% mental."

----------
"Larry Linson" <bo*****@localhost.net> wrote in message
news:ty**************@nwrddc02.gnilink.net...
I hope that you haven't felt it necessary or desirable to start from scratch writing SQL in Access. Access gives you the Query Builder which is an
excellent, unpaid SQL-writing Assistant. I'll just assume that you're using the SQL as a communication vehicle, but that you saved yourself a great deal of time and effort by using File | Get External Data to link the tables in
the other database. If not, take a look at it, and I think you'll soon
"learn to love it" -- that is, unless you are an SQL hobbyist. <G>

I believe I'd create myself a local table with the numeric values and text
for the service type, and join those to the appropriate fields in
calShipment and calPackage in a MakeTable or Update Query, and do the same
for m_isPkgVoid field. Then again, I might just leave those fields numeric, and do the join only when I needed the text values for display in a Form or a Report.

(For a MakeTable or Update Query, create the Query as a Select, and in
Design View in the Query Builder, on the menu Query | Make Table or Update. However, see below: you may not need to create a temporary table.)

Your expression for manipulating the date looks good to me, but this, too,
can be accomplished without any temporary or intermediate table, in the
Query that you use as RecordSource for the Form or Report where the data is viewed and/or used.

On the other hand, if the tables from which you are extracting the
information are transitory in nature, and may not be around when you need
the information, bringing that information in to a local table (not
necessarily temporary) would obviously be a good idea. If you maintain past data in your local table(s), you may be able to get "extra value" by
analyzing it at some future time.

A Service Type table would consist of two fields (or more, if you think you may need additional description or information): the service type number,
and service type name. You'd join it to the calShipment.m_serviceType field on service type number, but pull the service type name down into the Query
Builder Grid. The text for m_isPkgVoid could be handled the same way, or
created as a Calculated Field in the Query using the IIf statement you
cited.

If I haven't been clear enough, follow up and I'll try to clarify.

Larry Linson
Microsoft Access MVP

Nov 12 '05 #5
"Bob" <rt********@comcast.net> wrote in message
news:eg********************************@4ax.com...
I am still trying to learn how to use Access for other than storing
the data

What I am doing in Visual is

I have one db that I am using a query to pull data from 3 tables based
on the primary and foreign keys. In the db 2 of the fields in the
calShipment table and 1 in the calPackage table are the ones I am
addressing.

The Switch() function might be what you need.
Nov 12 '05 #6
Bob
Where would I use the Select Case in Access?

On Wed, 24 Sep 2003 01:46:45 -0600, "Reggie"
<newsgroups@no_spam.comcast.net> wrote:
Have you tried a Select Case statement:

Dim intShipmentType as Integer
Dim intPackageVoid as Integer
intShipmentType = calShipment.m_serviceType
intPackageVoid = calPackage.m_isPkgVoid

Selct Case intShipmentType
Case 2
strIIF = "Next Day Air"
Case 19
strIIF = "Next Day Air AM"
Case Else
strIIF = "whatever"
End Select

Selct Case intPackageVoid
Case 0
sstrIIF = "Sent"
Case 1
sstrIIF = "Voided"
Enb Select

Reggie

"Half this game is 90% mental."

----------
"Larry Linson" <bo*****@localhost.net> wrote in message
news:ty**************@nwrddc02.gnilink.net...
I hope that you haven't felt it necessary or desirable to start from

scratch
writing SQL in Access. Access gives you the Query Builder which is an
excellent, unpaid SQL-writing Assistant. I'll just assume that you're

using
the SQL as a communication vehicle, but that you saved yourself a great

deal
of time and effort by using File | Get External Data to link the tables in
the other database. If not, take a look at it, and I think you'll soon
"learn to love it" -- that is, unless you are an SQL hobbyist. <G>

I believe I'd create myself a local table with the numeric values and text
for the service type, and join those to the appropriate fields in
calShipment and calPackage in a MakeTable or Update Query, and do the same
for m_isPkgVoid field. Then again, I might just leave those fields

numeric,
and do the join only when I needed the text values for display in a Form

or
a Report.

(For a MakeTable or Update Query, create the Query as a Select, and in
Design View in the Query Builder, on the menu Query | Make Table or

Update.
However, see below: you may not need to create a temporary table.)

Your expression for manipulating the date looks good to me, but this, too,
can be accomplished without any temporary or intermediate table, in the
Query that you use as RecordSource for the Form or Report where the data

is
viewed and/or used.

On the other hand, if the tables from which you are extracting the
information are transitory in nature, and may not be around when you need
the information, bringing that information in to a local table (not
necessarily temporary) would obviously be a good idea. If you maintain

past
data in your local table(s), you may be able to get "extra value" by
analyzing it at some future time.

A Service Type table would consist of two fields (or more, if you think

you
may need additional description or information): the service type number,
and service type name. You'd join it to the calShipment.m_serviceType

field
on service type number, but pull the service type name down into the Query
Builder Grid. The text for m_isPkgVoid could be handled the same way, or
created as a Calculated Field in the Query using the IIf statement you
cited.

If I haven't been clear enough, follow up and I'll try to clarify.

Larry Linson
Microsoft Access MVP


Nov 12 '05 #7
Bob, You can use it in place of the IIF statement you designed. I'm not
sure from your post if you are doing it in VB or Access. At any rate it
works in both. I'm not exactly sure how/when you're using it so I can't say
for sure where to place it. This was just to give you a cleaner way of
building your string. If you do as Larry suggested and pull/link the table
into access, simply design and update query. You can set the "update to"
value to the return value of a function placed in a standard module.
--
Reggie

"Half this game is 90% mental."

----------
"Bob" <rt********@comcast.net> wrote in message
news:hh********************************@4ax.com...
Where would I use the Select Case in Access?

On Wed, 24 Sep 2003 01:46:45 -0600, "Reggie"
<newsgroups@no_spam.comcast.net> wrote:
Have you tried a Select Case statement:

Dim intShipmentType as Integer
Dim intPackageVoid as Integer
intShipmentType = calShipment.m_serviceType
intPackageVoid = calPackage.m_isPkgVoid

Selct Case intShipmentType
Case 2
strIIF = "Next Day Air"
Case 19
strIIF = "Next Day Air AM"
Case Else
strIIF = "whatever"
End Select

Selct Case intPackageVoid
Case 0
sstrIIF = "Sent"
Case 1
sstrIIF = "Voided"
Enb Select

Reggie

"Half this game is 90% mental."

----------
"Larry Linson" <bo*****@localhost.net> wrote in message
news:ty**************@nwrddc02.gnilink.net...
I hope that you haven't felt it necessary or desirable to start from

scratch
writing SQL in Access. Access gives you the Query Builder which is an
excellent, unpaid SQL-writing Assistant. I'll just assume that you're

using
the SQL as a communication vehicle, but that you saved yourself a great

deal
of time and effort by using File | Get External Data to link the tables in the other database. If not, take a look at it, and I think you'll soon
"learn to love it" -- that is, unless you are an SQL hobbyist. <G>

I believe I'd create myself a local table with the numeric values and text for the service type, and join those to the appropriate fields in
calShipment and calPackage in a MakeTable or Update Query, and do the same for m_isPkgVoid field. Then again, I might just leave those fields

numeric,
and do the join only when I needed the text values for display in a Form
or
a Report.

(For a MakeTable or Update Query, create the Query as a Select, and in
Design View in the Query Builder, on the menu Query | Make Table or

Update.
However, see below: you may not need to create a temporary table.)

Your expression for manipulating the date looks good to me, but this,
too, can be accomplished without any temporary or intermediate table, in the
Query that you use as RecordSource for the Form or Report where the datais
viewed and/or used.

On the other hand, if the tables from which you are extracting the
information are transitory in nature, and may not be around when you

need the information, bringing that information in to a local table (not
necessarily temporary) would obviously be a good idea. If you maintain

past
data in your local table(s), you may be able to get "extra value" by
analyzing it at some future time.

A Service Type table would consist of two fields (or more, if you think

you
may need additional description or information): the service type number, and service type name. You'd join it to the calShipment.m_serviceType

field
on service type number, but pull the service type name down into the Query Builder Grid. The text for m_isPkgVoid could be handled the same way, or created as a Calculated Field in the Query using the IIf statement you
cited.

If I haven't been clear enough, follow up and I'll try to clarify.

Larry Linson
Microsoft Access MVP

Nov 12 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Paradigm | last post by:
Does anyone know how I can use vba in access to run a script that is stored as a file. I can make a connection to mysql database and run sql statements but this sql statement is very long (creates...
2
by: Hasan Ammar | last post by:
Is it possible to set up hotkeys using onkeypress? I know it can be done with the usual alphanumeric keys, but what about function keys? or using ctrl/alt combinations? Does anybody have a...
4
by: Skully Matjas | last post by:
I am using the following code (created by the wizard) to allow to bring my form to a particular entery. But when I edit the entery (ex: put new information into a blank cell), it puts that record...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
4
by: James | last post by:
I have a VB windows forms application that accesses a Microsoft Access database that has been secured using user-level security. The application is being deployed using No-Touch deployment. The...
2
by: csgraham74 | last post by:
Hello, im using MS Access as a front end to link to MYSQL. although this is possibly an Access issue i thought someone would be able to help me. the error message "ODBC--insert on a linked table...
1
by: garry.oxnard | last post by:
Can anyone help me to solve a problem which involves switching from Access to Excel (then back to Access) programatically please? I have an Excel template which, on open, also opens an Access...
3
by: Clearview | last post by:
This is my first post to the forum and hoping I can get help as I have spent a way too much time on this problem, and thinking it is probably something really simple to resolve. I am using Access...
0
MMcCarthy
by: MMcCarthy | last post by:
Rather than using the Access design view change the view to SQL. I am going to attempt to outline the general syntax used for SQL queries in Access. Angle brackets <> are used in place of some...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.