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

next letter in alphabet 1

Status
Not open for further replies.

Earth

Technical User
May 8, 2000
59
AU
I have a key field which has a lower-case letter as its value. ie. the first record's field = 'a', the second 'b', the third 'c' etc etc.<br><br>I want to have a method for automatically creating this character, as opposed to making the user type in the new value.<br><br>Obviously, the first record will automatically be 'a', but from there, how do I 'increment' a character value? If it was an integer, it would obviously be new = old + 1, but I'm not sure how to do it with characters. I hope it's just a one line of code situation, but....<br><br>thanks.<br>
 
I hope I can explain this:<br><br>I'm not sure what you are going to do when you reach the letter &quot;z&quot;, so I'm assuming you are going to start over. If not maybe this will still help you.<br><br>This uses the On Open event of a form to calculate the next character:<br><br>Private Sub Form_Open(Cancel As Integer)<br>Dim intLast As Integer<br>Dim intNext As Integer<br><br>intLast = Asc(DLast(&quot;YourTable&quot;, &quot;YourField&quot;))<br>If intLast = 122 Then intLast = 96 'If letter &quot;z&quot; 96+1= letter &quot;a&quot;<br>intNext = intLast + 1<br><br>Me![YourKeyField] = Chr(intNext)<br>End Sub<br><br>You will need to substitute the names &quot;YourTable&quot;, &quot;YourField&quot;, and &quot;YourKeyField&quot; for the actual names of your objects. <p>Ricky Hicks<br><a href=mailto: rdhicks@mindspring.com> rdhicks@mindspring.com</a><br><a href= > </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top