472,133 Members | 1,113 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,133 software developers and data experts.

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 1477
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

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.