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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Query - Filtering 2

Status
Not open for further replies.

ItIsHardToProgram

Technical User
Mar 28, 2006
946
CA
Hey every one!


I have a question about possibilities with VBA queries. I was wondering if it was possible to strip a specific field from its few last characters in a query. The environment is access.

For example, the specific field looks like 20080512-1-5-2.

Every '-' is a seperator for different information in the same field.

Is it possible to strip the field from '-1-5-2' through a query, without modifying the actual field or creating a field. The query would return something like 20080512.

I can think of many ways of doing it through VBA, i.e. forcing the query in a virtual table and working from there, but I am really trying to figure out a more straightforward way, or if I may the "best" way of doing this.

Thanks for all your ideas and inputs. If you could just get me started on ideas, without necesserely posting the whole code, it would be much appreciated, I have some learning to do ;)

Ty everyone, Julien Roy

"Knowing that you know is the greatest sign of stupidity, knowing that you are ignorant is the best proof of intelligence.
 
A starting point:
Code:
SELECT yourSpecificField, Left(yourSpecificField, InStr(yourSpecificField, "-") - 1) AS StrippedField
FROM yourTable
WHERE yourSpecificField Like '*-*'

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Assuming you're working in Access?
You don't need VBA.
Code:
Keep text on the left
Label: Left([Field],InStr("-",[Field])-1)
Or, on the right
Label: Right([Field],Len([Field]-InStr("-",[Field]))
 
Thanks alot guys, I knew there was a simple way to do this, did not think it could be done directly in the query!

Have a star, even though you got beat to the punch !

"Knowing that you know is the greatest sign of stupidity, knowing that you are ignorant is the best proof of intelligence.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top