View Single Post
  #7  
Old August 11th, 2004, 04:58 PM
tina
external usenet poster
 
Posts: n/a
Default How to phrase If/Then clauses in the control source field

yes, Sco, i did miss the reference in the header. the post began by talking
about "Parsing strings from one field into many", so i assumed the poster
was working on code to break out data from a single table field into several
fields in another table (not *show* data in a form's calculated control).
and i assumed he pretty much knew how to break out the data, and was just
looking for a more elegant function to replace whatever he was already
using.
well, you know what they say about "assuming..."! g
at any rate, your instructions were about as complete as could be asked for;
i'm glad you stepped in to help further.


"M.L. Sco Scofield" wrote in message
...
Well anonymous,

If you're going to be dabbling with these kinds of things, I highly
recommend getting some Access books and doing some studying.

I'd recommend getting "Beginning Access 2002 VBA" by Wrox. (The 2003 book

is
not out yet.)

You've gotten some perfectly usable answers in both your first thread and
this thread. (BTW, please don't start a new thread for the same problem.

You
should have posted to the first thread saying you didn't understand their
answer and ask for clarification.)

The problem with the answers you've gotten is that they are not complete.
They unfortunately assumed that you had a basic understand of Access and a
little VBA coding.

In one of your posts you ask for an If-Then "template." There is no such
thing. The "syntax" for an If-Then structure is very clearly explained in
the help file. If you need more than that, read the book I mentioned

above.

There is no syntax error in the code that Tina posted. Any syntax errors

you
are getting are from how you are trying to use the code. Which, BTW, you
never mentioned. To understand how to use the code Tina posted, (and the
code in the replies in the other thread,) you need to read the above book.

In the mean time, (and *not* a replacement for you getting and reading the
above book,) I'm going to make some guesses from the subject line of your
post.

1 - You want a finished solution, not some pointers.

2 - Tina missed the words "control source" in the subject line or maybe

she
would have given you a "complete" solution.

3 - She was expecting you to replace "FieldOrVariable" and "CodeString" in
her code with *your* actual names.

Here is how Tina's code needs to be completed to work in a control source:

'~~~ Start Code ~~~
Public Function ReturnYear(CodeString)

Dim intYear As Integer

intYear = Left(CodeString, 1)

Select Case intYear
Case 6 To 9
ReturnYear = 1990 + intYear
Case 0 To 5
ReturnYear = 2000 + intYear
End Select

End Function

'~~~ End Code ~~~

1 - Copy and paste this code into the body of a standard code module (From
the database window, select Modules and click new.)

2 - Close the code window and save the code module as basMyFunctions.

3 - In the control source of your text box, put:

=ReturnYear([YourFieldName]))

And replace "YourFieldName" with *your* field name that has the code in

it.

4 - Purchase "Beginning Access 2002 VBA"

5 - Read it.

Bottom line, as someone else mentioned, you shouldn't be messing with

fields
that are combinations of separate information.

Separate information should be in *separate* fields.

Hitting the tab key during data entry is *not* that big a deal.

And it is *not* something you should program around for some kind of
perceived convenience.

Good luck.

BTW, did I mention you need to buy and read "Beginning Access 2002
VBA"???...

Sco

M.L. "Sco" Scofield, Microsoft Access MVP, MCSD, MCP, MSS, A+
Useful Metric Conversion #17 of 19: 1 billion billion picolos = 1 gigolo
Miscellaneous Access and VB "stuff" at www.ScoBiz.com


wrote in message
...
I tried it but it gave me a syntax error message. Is
there a general if/then template?
-----Original Message-----
Dim intYear As Integer
intYear = Left(CodeString, 1)
Select Case intYear
Case 6 To 9
FieldOrVariable = 1990 + intYear
Case 0 To 5
FieldOrVariable = 2000 + intYear
End Select

you'll have to tweak it to work in your specific

circumstances, but that
should get you started.

hth


wrote in message
...
Hello,
This is a continuation of an earlier thread

about
Parsing strings from one field into many. I making a
database,that contains five fields of overlap and to

make
the data entry easier I am trying to automate some of

it.
I have a code field, and then four other fields whose
information can be derived from the code ((codelooks

like
this: 01MP, and has four parts. The first number refers
to the year 2000, the second number refers the season

of
the year (spring), the third to type of media (a
magazine), and the fourth the genre (politics).))

Anyway,
my problem lies in the fact that the code only has one
digit for the year, and the time span is from 1996 to
present. so how could one phrase an expression that
essentially says: if the first digit of the code string
is =6 but =9, add the value to 1990, and if the value
is =0 but =5 add it to 2000 (a short term solution;

the
code thing will eventually be revised). Thanks for any
help or info you can provide!


.