ID incrementation problem.
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: ID incrementation problem.

  1. #1
    Join Date
    Mar 2011
    Posts
    34

    ID incrementation problem.

    can you help me, i dont know how to put a letter into my incrementation code. for example my StudentID is 20110001 i want to make it SN20110001...when i tried to do like this
    If Len(holdid) = 1 Then
    txtempid.Text = "SN" & Format(Date, "yyyy") & "000" & Val(ID) + 1

    my program doesnt want to increment.




    Code:
    Call ClearForm
    EditFlag = False
    RSconn1 "select * from tblempinfo order by EmployeeID asc"
    
    If RS1.EOF = False Then
    For ctr = 0 To RS1.RecordCount - 1
    
    
    
    tempid = Right(RS1(0), Len(RS1(0)) - 4)
    
    If Val(tempid) > Val(ID) Then
    ID = tempid
    
    End If
    
    RS1.MoveNext
    If RS1.EOF Then
    Exit For
    
    End If
    
    Next
    
    holdid = Val(ID)
    
    If Len(holdid) = 1 Then
    txtempid.Text = Format(Date, "yyyy") & "000" & Val(ID) + 1
    
    ElseIf Len(holdid) = 2 Then
    txtempid.Text = Format(Date, "yyyy") & "00" & Val(ID) + 1
    
    ElseIf Len(holdid) = 3 Then
    txtempid.Text = Format(Date, "yyyy") & "0" & Val(ID) + 1
    
    ElseIf Len(holdid) = 4 Then
    txtempid.Text = Format(Date, "yyyy") & Val(ID) + 1
    
    Else
    
    txtempid.Text = Format(Date, "yyyy") & "0001"
    End If
    End If
    
    
    Call Enable
    Y = 1
    End Sub

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,875

    Re: ID incrementation problem.

    Year() works

    Code:
    ? format(year(now)+2,"####")
    Year(Now) Mod 2000 would be 11
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Mar 2011
    Posts
    34

    Re: ID incrementation problem.

    how could i put SN before the number?

  4. #4
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,875

    Re: ID incrementation problem.

    Concatenate strings with &

    Code:
    Format(Sn,"###") & Format(Year(Now),"####")
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center