Testing String Values

G

GLT

Hi,

I have some code that tests two string varibles (strFeild1 and strFeild2) -
both are declared as string varibles.

When I step through this code, and both strings are equal to the first
condition which is (strFeild = "Totals For" and strFeild2 = "Job"), then it
gets ignored and jumps to the second condition.

I am printing the debug lines as I step through the code, and when I hover
the mouse over each feild, when the values are "Totals For" and "Job", it
still will not get picked up by the correct condition testing...

The code below is a cut down version of the code I am using...

If (strFeild1 = "Totals For") And (strFeild2 = "Job") Then
Debug.Print strFileNo & " " & strFeild1 & " " & strFeild2

<Execute some VB>

ElseIf (strFeild1 = "Totals For") And (strFeild2 <> "Job") Then
Debug.Print strFileNo & " " & strFeild1 & " " & strFeild2

<Execute some VB>

End If


Any help is always greatly appreciated...

Cheers,
GLT
 
D

Douglas J. Steele

Are you sure that the fields contain "Totals For" and "Job", and not, say,
""Totals For " or " Job". In other words, might there be spaces (or
other non-visible characters) in the variables?
 
G

GLT

Hi Douglas, thanks for your response...

As a test I just modified the table being read in to only have records where
the fields are only "Totals For" and "Job". When the table only has these
fields in it, then it works OK. But when my table has both sets of data
where strFeild2 = "Job", and strFeild2 <> "Job", then it fails to work -
perhaps this is a logic problem...
 
R

Rastro

First of all:
Is it strFeild2 or strField2?
Did you declare your variables?

You could try this:
ElseIf (strFeild1 = "Totals For") And Not (strFeild2= "Job")

This, I think, is more accurate since you need in the second term that
strField2 will NOT be "Job"

Rastro
 
G

GLT

Hi Gentleman,

Thanks for your response - I have worked out what the problem is but still
working on a solution:

The VB code is processing through a recordset, and when the value of
strfeild1 = "Totals For", then it processes these records (inserting into a
seperate table) until it finds a value called "Job No".

There are two different types of "Totals For" data, and they each need to be
split into their own unique tables.

Normally, ther data looks like this:

Totals For
..
..<Data>
..
Job No

What I discovered was that sometimes I have two "Totals For" that appear
directly after each other:

Totals For
..
..<Data>
..
Totals For
..
..<Data>
..
..Job No

The two 'Totals For' above are two different types of totals data and need
to be in seperate tables. I created some VB code that scans through the
table, and renames the second "Totals For" to "Totals for Job", so now my
data looks like this:

Totals For
..
..Data
..
Totals For Job
..
..Data
..
..Job No

But its having loops inside of loops and breaking out of these loops when
strFeild1 = "Job No" that I am having difficulty with.

Cheers,
GLT
 

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