it might help you to understand it, if you first write the expression using
"hard-coded" text values, as
"[altec_maxitem] = 'something' Or [altec_switchno] = 'something else'"
that's a WHERE clause. note how the double quotes enclose the whole
expression, and the single quotes enclose each hard-coded value. now you
need to replace the hard-coded text values with control references. start by
"closing" the string before and after each hard-coded value, with a double
quote, as
"[altec_maxitem] = '" something "' Or [altec_switchno] = '" something else
"'"
note how the single quotes are *inside* of each opening/closing set of
double quotes. now you have three separate strings to connect - just be
patient, we'll get there. replace the hard-coded values with the control
references, as
"[altec_maxitem] = '" Me.txtPartNumber "' Or [altec_switchno] = '"
Me.txtPartNumber "'"
now you have to connect the three strings and the control references, using
the & concatenator *outside of the strings* and making sure to leave a space
before and after each concatenator, as
"[altec_maxitem] = '" & Me.txtPartNumber & "' Or [altec_switchno] = '" _
& Me.txtPartNumber & "'"
i added the line continuation character ( _ ) just to make it clear that the
expression runs all on one line (unless you use the continuation character
to break it up).
hth
Luke Bedggood said:
Thank you both for your assistance
for whatever reason, Tinas code works - now to understand why!
thanks again
regards
Luke
tina said:
try
PMFJI, but your expression looks to me like the "Or" is outside the string.
try
stLinkCriteria = "[altec_maxitem] = '" & Me.[txtPartNumber] _
& "' Or [altec_switchno] = '" & Me.[txtPartNumber] & "'"
hth
Hi Allen
well I am learning something anyway, thanks for the tips
your original suggestion for code came up with an error which i guess may
be
because of the quotes on the end of the bracket and the use of a single
aphostophy as the second character on the second line
stLinkCriteria = ("[altec_switchno] = """ & Me![txtPartNumber] & _
"'"") Or ([altec_maxitem] = """ & Me![txtPartNumber] & """)"
I have been basing my thing around this code - what stumps me the most is
that the working syntax of:
stLinkCriteria = ("[altec_maxitem] = """ & Me![txtPartNumber] & "")
returns [altec_maxitem] = "sw200-1"
or the working syntax of
stLinkCriteria = ("[altec_switchno] = """ & Me![txtPartNumber] & "")
returns [altec_switchno] = "sw200-1"
(Both the above use txtPartNumber = SW200-1):
both work as individual lines, but when cojined, they return a single
empty
value (line-return in Immediate window).
this code is:
stLinkCriteria = ("[altec_maxitem] = """ & Me.[txtPartNumber] & """") _
Or ("[altec_switchno] = """ & Me.[txtPartNumber] & """")
I think my problem may be down to getting the Or statement to work
effectivly.
Now I am lost!
:
So did you trace where the code went, using F8?
YOu really need to debug this for yourself, but your string is not the
same
as suggested in the earlier post:
stLinkCriteria = ("[altec_switchno]=" & "'" & Me![txtPartNumber] &
_
"'") Or ("[altec_maxitem]" = "'" & Me![txtPartNumber] & "'")
Hint: & "" is adding nothing to the string.
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to group, rather than allenbrowne at mvps dot org.
message
you learn a little more every day - thanks for that, a useful tip
however it demonstrates my code is still duff as it returns into the
immediate window nothing other than a line-return regardless of which
part
number type is used. again if i 'rem out the part after the Or
statement
it
works fine, and likewise if i use the [altec_maxitem] field it works
fine.
from this i know each statement on its own works as desired, the
problem
being to get them to work together - the code is as follows, and it
really
has me stumped!
stLinkCriteria = ("[altec_switchno]=" & "'" & Me![txtPartNumber] &
_
"'") Or ("[altec_maxitem]" = "'" & Me![txtPartNumber] & "'")
thanks for your time on this so far
:
If you can't get the program to stop on error (due to your error
handlers),
then just add this line to your code:
Stop
Then the code will stop at that line when it executes, and you can
press
F8
to step through each line, using the Immediate Window to query the
variables, see what is wrong, and even trace where the error handler
is
jumping to.
message
Absolutley - and I can understand why you have suggested it,
however
the
code
I have written as per the previous post is terminating the run of
the
program
before the debug command. I found an article about using 'On Error
Resume
Next', which has enabled the program to run past the point of my
dodgy
code,
and has left the Immediate Window blank - this I was not expecting,
so
I
know
it is the Or statement that is causing the problem (it 'half' works
if
I
rem
out the Or aspect of the code)
the problem is that it is not reporting anything back to the
Immediate
Window to enable me to deduce where i am going wrong