hello guys need some help, i need to generate id the problem is i cannot get the last row from database

logical view

DATABASE
tbloutlet
PCSO20121
PCSO20122
PCSO20123

NOW
need to get
"PCSO20123"
select the last character '3' using mid
after selecting '3' convert to int and add to 1 VAl=3+1
"PCSO2012" & VAL

Main problem cannot select last row from the database "PCSO20123"

rs.Open "select max(OUTLET_ID) as IDS from tblOutlet", conn, adOpenStatic, adLockReadOnly
'ids = rs.Fields("IDS")
If rs.BOF And rs.EOF Then
    nonIds = "PCSO" & strYear & "1"
    txtOutletID.Text = ids
    Else
        genid = Mid$(rs.Fields("IDS"), 8, 1)
        inty = CInt(genid) + 1
        idhand = "PCSO" & strYear & CStr(inty)
    End If
    txtOutletID.Text = genid
   
End Sub

Recommended Answers

All 2 Replies

Store the last number generated somewhere -- in another table or an initialization file.

Since you are always concatenating the generated number to a fixed string, you need to generate only the number part from DB. Using the logic of Max(field)+1 should work fine for you.

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.