hi,

i had one field in the table(field name: crseid).

for example,i am having 500 courses.i want to start the crseid from :6000(4 digit number)

output:
6001
6002
6003
.
.
.
.
6500

this value must be inserted into my table.


thanks in advance

If you do it by vb with a textbox

Function GetId(TableName As String, FieldName As String, Optional Criteria As String)
    Dim rs As New ADODB.Recordset
        If Criteria = "" Then
        rs.Open "Select max(" & FieldName & ") from " & TableName, conn, adOpenDynamic, adLockReadOnly
        GetId = IIf(IsNull(rs.Fields(0)), 0, rs.Fields(0))
        Else
            rs.Open "Select max(" & FieldName & ") from " & TableName & " where " & Criteria, conn, adOpenDynamic, adLockReadOnly
            GetId = IIf(IsNull(rs.Fields(0)), 0, rs.Fields(0))
        End If
End Function
Private Sub Txtcourse_LostFocus()
txtcrseid.Text = Val(GetId("table1", "[crseid]", " course_name ='" & Txtcourse.Text & "'")) + 1
End Sub

here course name mean if you have several course name. when you type the course name in txtcourse(textbox) it will increase crseid automatically.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.