Private Sub cmdAdd_Click()
clearform
MasterAction = "ADD"
resetFormControl True, vbWhite
blnchangemade = False
If empdeptrs.RecordCount > 0 Then
empbookmark = empdeptrs.Bookmark
End If
'Generate_no
Dim rsdb As Recordset
Set rsdb = employeedb.OpenRecordset("Select max(auid) as cntr from empPosition", dbOpenSnapshot)
' Set rsdb = employeedb.OpenRecordset("Select Max(" & strY & ") from " & strX & "")
If rsdb.RecordCount > 0 Then
rsdb.MoveLast
' Me.lbltry.Caption = rsdb!cntr + 1
Me.Text1 = rsdb!cntr + 1
'Me.Text1 = 1
' Else
' Me.Text1 = 1
End If
empdeptrs.AddNew
Text1.Enabled = True
Text2.Enabled = True
Text3.Enabled = True
Text2.SetFocus
OktoExit = False
End Sub
============================
May TAO po ba dito???
pede mag pa tulong...
ask ko lang po kung paano po kumuha ng maxID i mean na max ID
HAL: I add record 1 - 10 then i delete record #9 then the #9 record will be automatically available.
dapat wen i click the ADD button instead of 11 ang lalabas sa textbox. mag kakaroon ng message box "OPTION" asking for the number that is not yet avail...
may makaktulong po ba?
bakit kelangan mo pa gamitin ang #9, counter lang naman yan so leave it as is
bakit di mo namang gamitin yung autonumber ng database mo
it will take lots of effort ang processing time kasi pag nag implement ka ng ganyan
kung may realtionship kasi yung table na yan, di mo dapat i delte yung #9, just mark it as inactive
pero kung gusto mo idelete ok lang
ang solution dyan is magahanap ka ng UNUSED na number
by looping, one by one po yun
imagine kung may 1million records ka.
mag loop ka sa;
if n = n+1 then
else
endif
obsseesed din ako dyan dati sa numbering noong bata pa ako sa programming
pero ngayon, meron lang akong autonumber at isang autogenerated number/string na series lang
pero still using MAX sa sql
di naman importante na sunod sunod yan
importante is naka index at unique
isang technique din ay i store mo yung ID ng nadelete na record
at gamitin mo yun muna before generating another
pero still the same, effort parin sa part mo to code, debug and test
the more code, the more tendency for bugs