PDA

View Full Version : Exclude characters in variable string?



bguidry
01-02-2013, 03:32 PM
I am trying to set a field, within a temporary table on a subform, equal to certain string characters from a textbox on a mainform. We enter values in the textbox like "ABC-ABCD-1". The VBA code copies this to the temporary table field and adds incremental integers to the end of the string, such as:
rstLoadTable!Field = textbox & Format(Str(intCount))but now need to have it exclude the integer after the second "-" character (or possibly simply the last character in the string; but not by count of the leftmost characters, as this may change). Can someone help me figure out how to exclude the tailing characters that follow the second "-" from the textbox string when setting the rstLoadTable!Field equal to it?

BrianMH
01-03-2013, 01:10 AM
If you want to just take off the last character try


left(yourVariable,len(yourVariable)-1)


This should take into account if your string length changes.

If there may be more than one character on the integer then the below should work.

left(yourVariable,instrrev(yourVariable,"-"))

bguidry
01-03-2013, 07:42 AM
Thanks, Brian. That worked perfectly. I was not familiar with the "instrrev" function.