Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB6 COMAPI query 2

Status
Not open for further replies.

Bluejay07

Programmer
Mar 9, 2007
780
CA
Hello,

I looking for proper syntax when performing a query for a range. Essentially I am referencing UPEREG and want to search for a range with FILCREATNO.

Ex.
Code:
UPEREG.Browse "FILCREATNO >= 1 and FILCREATNO <= 5"  & "", True
Do While UPEREG.GoNext
  ...
Loop

If at first you don't succeed, then sky diving wasn't meant for you!
 
FILCREATNO is a string, so you need to use quotes around the value you are searching for.
 
Thanks for the feedback.
Is my syntax correct for the browse?
Code:
UPEREG.Browse "FILCREATNO >= " & """1""" & " and FILCREATNO <= " & """5"""  & "", True
Also, @tuba, if I use .fetch will that not return a single value rather and navigating through the range that I am trying to obtain?

If at first you don't succeed, then sky diving wasn't meant for you!
 
Tuba, are you suggesting Do while .Fetch?

If at first you don't succeed, then sky diving wasn't meant for you!
 
Code:
UPEREG.Browse "FILCREATNO >= ""1"" and FILCREATNO <= ""5""", True
 
GoNext and Fetch are essentially the same, GoNext, GoTop, GoPrevious & GoBottom where introduced in newer versions. Previously only Fetch was available.
You will not see any difference using the one or the other.
 
Thanks to both you.
Thanks for the quote correction ettienne.
Sorry tuba, thinking about multiple projects and might be a bit slow today.


If at first you don't succeed, then sky diving wasn't meant for you!
 
Technically, unless there are embedded spaces in the strings, you don't need the enclosing quotes. But, it's a good habit to get into.
 
Now I know why I had the extra quotes. It's because I am using values from a text box. Can I please get the proper syntax again? Eg. replace 1 with trim$(pzeFrom.text) and 5 with trim$(pzeTo.text).

I've been trying and it's not working.


If at first you don't succeed, then sky diving wasn't meant for you!
 
Code:
UPEREG.Browse "FILCREATNO >= """ & trim$(pzeFrom.text) & """ and FILCREATNO <= """ & trim$(pzeTo.text) &  """", True
 
Thank you very much. That is what I needed. I just couldn't get the placement right.

If at first you don't succeed, then sky diving wasn't meant for you!
 
This will also work:

UPEREG.Browse "FILCREATNO >= " & Val(pzeFrom.text) & " and FILCREATNO <= " & Val(pzeTo.text), True
 
Thanks Tuba but as ettienne mentioned it's a string field not a numeric field. Converting it using val() doesn't seem to work. I'm assuming its because of the leading zeros in the field.


If at first you don't succeed, then sky diving wasn't meant for you!
 
Details, details...

UPEREG.Browse "FILCREATNO >= " & Format(Val(pzeFrom.text),"0000") & " and FILCREATNO <= " & Format(Val(pzeTo.text),"0000"), True

Then the user doesn't have to enter the leading zeroes.
 
Thank you Tuba and thank you Ettienne.
Between both of your efforts I have my code segments working. Your comments are greatly appreciated.

If at first you don't succeed, then sky diving wasn't meant for you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top