ms access - Have autonumbered column restart value from 1 after primary key value changes? -
i have 2 tables, call them po , po_li. there column in po called po# primary key, , in 1 many relationship po# column in po_li (the 1 being in po). in po_li, other columns line#, description , lineamount.
how can reset number 1 every new po #?
can done while still using autonumber?
can done in ms-access gui or vba code required?
you cannot manually edit autonumber field or change starting value. best bet maybe use vba max line number , increment it, , if you're using new po start @ 1. put vba in afterupdate event of po field.
you this:
dim db database dim rec recordset dim rec2 recordset dim myval integer set db = currentdb set rec = db.openrecordset("select linenum mytable po = '" & me.txtpo & "' group po") 'if there no records returned, start @ 1. otherwise, increment. if rec.eof = true myval = 1 else set rec = db.openrecordset("select max(linenum) mytable po = '" & me.txtpo & "'") myval = rec(0) + 1 endif
myval number write linenum. of course, you'll need change variables , such what's on forms , in tables, should idea.
Comments
Post a Comment