Can anyone give me an idea on why this is not working? I have a "Record ID" textbox in a add form that I want it to find the next available number that is not used for the user. I can't seem to get this to work because it keeps showing "001" as the next number when there is record with that number. Here the code I am using:
<%@ Language=VBScript %>
<%
'Create DSN Less connection to Access Database
'Create DBConn Object
Set DBConn = Server.CreateObject("adodb.connection"
DBopenString = "DRIVER={Microsoft Access Driver (*.mdb)}; "
DBopenString = DBopenString & "DBQ=" & Server.Mappath("ErrorProofing.mdb"
DBConn.Open DBopenString
Action = Request.QueryString("action"
select case Action
case "add"
DeptNum = Request.QueryString("DeptNum"
DeptName = Request.QueryString("DeptName"
SQLstmt = "SELECT SequenceNum FROM tblSequencer WHERE Dept = " & DeptNum & " AND YearVal = " & Year(date) & ";"
Set RS = DBconn.Execute(SQLstmt)
if not RS.eof then
SeqVal = RS("SequenceNum" + 1
else
SeqVal = 1
end if
if SeqVal < 10 then
seq = "00" & SeqVal
else
if SeqVal < 100 then
seq = "0" & SeqVal
else
seq = SeqVal
end if
end if
EntryDate = date
EPID = right(DeptNum, 2) & "-" & right(year(date),2) & "-" & seq
<%@ Language=VBScript %>
<%
'Create DSN Less connection to Access Database
'Create DBConn Object
Set DBConn = Server.CreateObject("adodb.connection"
DBopenString = "DRIVER={Microsoft Access Driver (*.mdb)}; "
DBopenString = DBopenString & "DBQ=" & Server.Mappath("ErrorProofing.mdb"
DBConn.Open DBopenString
Action = Request.QueryString("action"
select case Action
case "add"
DeptNum = Request.QueryString("DeptNum"
DeptName = Request.QueryString("DeptName"
SQLstmt = "SELECT SequenceNum FROM tblSequencer WHERE Dept = " & DeptNum & " AND YearVal = " & Year(date) & ";"
Set RS = DBconn.Execute(SQLstmt)
if not RS.eof then
SeqVal = RS("SequenceNum" + 1
else
SeqVal = 1
end if
if SeqVal < 10 then
seq = "00" & SeqVal
else
if SeqVal < 100 then
seq = "0" & SeqVal
else
seq = SeqVal
end if
end if
EntryDate = date
EPID = right(DeptNum, 2) & "-" & right(year(date),2) & "-" & seq