469,573 Members | 1,222 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,573 developers. It's quick & easy.

Embedding Left( ) into FindFirst criteria...

patjones
931 Expert 512MB
This is not a question, but rather an informational post about something I just solved. My issue was that I'm trying to use

Expand|Select|Wrap|Line Numbers
  1. rst.FindFirst (str1 & " = '" & txtLastNameSearch.Value & "'")
  2.  
My goal was to search through a table with a field fldNameLast, but only compare the leftmost int1 characters in this field to my text box value (txtLastNameSearch.Value). So originally I tried something like

Expand|Select|Wrap|Line Numbers
  1.  str1 = "Left([fldNameLast],int1)" 
But the VB compiler complained about the use of int1 (which is set earlier in the code). After playing around with it for a while, I settled on

Expand|Select|Wrap|Line Numbers
  1.  str1 = "Left([fldNameLast]," & int1 & ")"
And this works very well, at least for all the values of txtLastNameSearch.Value that I've tried so far. Seems like the main rule is to keep variables outside the quotes...
Nov 14 '07 #1
1 1401
Rabbit
12,516 Expert Mod 8TB
Thanks for sharing. What you ran into was a variable scope issue. Not all forms and functions can see every other forms' and functions' variables, which can be confusing to the uninitiated. Hopefully this will help other potential readers with problems.
Nov 14 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by cnlai | last post: by
1 post views Thread by Mike MacSween | last post: by
reply views Thread by Snoopy33 | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.