Chopping a variable letter off the end of a word

  • Thread starter BTU_needs_assistance_43
  • Start date
B

BTU_needs_assistance_43

So I discovered that not all my reports will go in order and sometimes they
will end with "a", "b", "c", or "d" instead of just "a". I had a working
program set up to chop off "a" if it was at the end. But now that I have
rewritten it to include more letters, the program still gives an output value
but never chops anything at all off the letter and I'm trying it with both an
If Then Else statement and an If Then Goto Else Goto statement. The program
runs successfully but gives the same wrong output both ways. Is my logic
faulty in this program? Can I not interlace functions like this? What is the
deal!?

IF/THEN/ELSE:

If Right(B62, 1) = "a" Then
rst![Total Shot Name] = Left([vShots], Len(vShots) - 1)
Else
If Right(B62, 1) = "b" Then
rst![Total Shot Name] = Left([vShots], Len(vShots) - 1)
Else
If Right(B62, 1) = "c" Then
rst![Total Shot Name] = Left([vShots], Len(vShots) - 1)
Else
If Right(B62, 1) = "d" Then
rst![Total Shot Name] = Left([vShots], Len(vShots) - 1)
Else
rst![Total Shot Name] = vShots
End If
End If
End If
End If



IF/THENGOTO/ELSEGOTO

If Right(B62, 1) = "a" Then GoTo CutShort Else GoTo Checkforb
Checkforb: If Right(B62, 1) = "b" Then GoTo CutShort Else GoTo Checkforc
Checkforc: If Right(B62, 1) = "c" Then GoTo CutShort Else GoTo Checkford
Checkford: If Right(B62, 1) = "d" Then GoTo CutShort Else GoTo SameName
CutShort: rst![Total Shot Name] = Left([vShots], Len(vShots) - 1)
SameName: rst![Total Shot Name] = vShots
rst.Update
 
J

Jack Leach

You might try the Select Case statement instead.

Select Case Right(B62, 1)
Case "a"
Dosomething
Case "b"
Dosomething
Case Else
Dosomethingelse
End Select.

Or maybe an If/Then/Elseif:

If Right(B62, 1) = "a" Then
DoSomething
ElseIf Right(B62, 1) = "b" Then
DoSomething
ElseIf Right (B62, 1) = "c" Then
DoSomething
Else
DoSomethingelse
End If

This is sometimes preferable to nested if statements.

hth
--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
J

John Spencer MVP

Well, it would help if you posted the entire procedure instead of a snippet.

Also, you should be able to change the snippet to

IF B62 Like "*[abcd]" Then
rst![Total Shot Name] = Left(vShots,Len(vShots)-1)
End IF

So are you saving the change in the value with
Rst.Update
which permanently changes the value in the table

What values are in vShots and B62? Are these fields in the recordset are
variables in your code?


John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top