detect addnew()

hi all

I have a button called save. onclick of this button i save the current record and then automatically do a addnew so that all the fields are blank and the user can add a new one and click on save again. if the user click save again it creates another blank record.

how do i detect if an empty record is already in there or not.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

you can query the database for a record which has a null value where you would normally have a value. If the number of records in the dataset is greater than 0 then there is one (or more) else you need to create one.

Happy coding!
Yeah, or if you let your users add more than one record/newRow at a time or the dataset won't be empty, store the dataset.table.rows.count and then check that value against the current dataset.table.rows.count when the user clicks Save again.

2 suggestions.  first: after they click save, popup a dialog asking if they want to create a new record, ... if no, send them back from whenst they came.  If your users are like mine (or me, even) ... they'll want evidence that clicking on Save actually saved something so they can happily leave that form.  If you don't ask they if they want to create a new one ... throw 'Record Saved' into a label or status bar or pop it up.

second: if your users are created new records and they have a save button ... (and you obviously don't want them sitting there clicking Save and creating empty or bad new records) ... i'd recommend you do something like

private sub save_click(sender/e)
    dim valid as boolean = validate_current()
    if Not valid then
         '// yell at the user.  bad user!  ... you can't add records without social-security #'s ... how are we supposed to Pay Them!?
         '// save.  and tell the user you did.
    end if
end sub

private sub validate_current()

dim IsValid as boolean = true

'// go thru your controls and see if all of the required values have been entered.  IsValid = False if you find something wrong ... ideally you'd tell the user exactly what they forgot to do, ofcourse.  if, as in my example above, you're entering people and they need social security numbers ... and the user doesn't enter one ... yell.  tho you might want to build some exceptions into the system so they just get a "Are you REALLY sure you want to add this person without a social security #???" dialog and you let them do it incase they're in a hurry ... and you nag them with alerts later  :P

return IsValid

end sub

sorry if none of my rambling was helpful.  just hoping to save another developer some headaches down the road  :P

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.