an access question time. have form bound table , want form allow adding new entries (not editing or deleting) clicking on "save" button. first problem record updated while editing textboxes. solution have has several problems
option compare database option explicit private bsaverecord boolean private sub btcreaterecord_click() bsaverecord = true me.tblumgmtuser_userdetailsid.value = me.tblumgmtuserdetails_userdetailsid.value me.tbsetuserhashpw = "12312" me.cbsetinitpw = true docmd.gotorecord , , acnext end sub private sub btresetrecord_click() resetrecord end sub private sub form_afterupdate() bsaverecord = false end sub private sub form_beforeupdate(cancel integer) if not bsaverecord cancel = true me.undo end if end sub private sub form_load() me.username.setfocus docmd.gotorecord , , acnewrec bsaverecord = false end sub private sub resetrecord() dim ccontrol control bsaverecord = false each ccontrol in me.controls if ccontrol.name "text*" ccontrol = vbnullstring next me.cbresponsible.value = false me.undo end sub
problem 1: have add hidden textboxes save values record want generated automatically
problem 2: id-column counts every time open form, if haven't added record previously
generally spoken solution doesn't feel robust , elegant. suggestions appreciated
many jon
you binding data entry form directly target table. result, when user enters data, edit table directly including creating new records. why id auto-increments (because user creating new records). current partial work-around use hidden textboxes store values.
your goal of data entry form sounds common scenario. try this:
first, not set target table form's source. leave source blank , fields unbound. since separate, user can't edit existing records or add new ones entering data. in fact, nothing happen if user enters data , closes form.
go ahead , make save button. button validate data make sure want, create , execute sql insert query add data target table.
Comments
Post a Comment