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 to increase the Computer Name by 1 letter or number 1

Status
Not open for further replies.

mlstewart

Instructor
Joined
Aug 20, 2004
Messages
58
Location
US
With help from some of the other memebers, I've got my database set up so that when a certain form opens, it displays the computer name in a label. Can someone help me out with some VBA code that will increase/increment the computer name by 1 letter or number? For example, if the computer name is "RJ123" then I want "SK234" to display in the label instead of the actual computer name. ("Z" should return a value of "A" and "9" should return a value of "1")



This is what I am using to get the computer name:

Private Sub Form_Open(Cancel As Interger)

ComputerNameLabel.Caption = Environ("ComputerName")

End Sub


Thanks!!
 
No one-liner but heres some VB code, not neat but should work for VBA. You question implies that only A-Z and 1-9 are valid characters the code reflects that.

Code:
Dim x As Integer
Dim mystring As String

mystring = Environ("ComputerName")

For x = 1 To Len(mystring)
   Mid(mystring, x, 1) = Chr(Asc(Mid(mystring, x, 1)) + 1)
   If Mid(mystring, x, 1) = "[" Then
        Mid(mystring, x, 1) = "A"
   ElseIf Mid(mystring, x, 1) = ":" Then
          Mid(mystring, x, 1) = "1"
   End If
Next

ComputerNameLabel.Caption = mystring

[blue]For some light entertainment have a look at thread222-620646 regarding "ENVIRON"[/blue]

 
Thanks! I really appreciate your help. It works great. Just what I needed!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top