[AccessD] AddNewRecord "Problem"

Darryl Collins darryl at whittleconsulting.com.au
Sun Oct 23 21:47:23 CDT 2011


Bill,

You can convert any of the new Macros to VBA code.  Open the form in design view and use the Convert Form's Macro to Visual Basic command.  I always do this now if I use a wizard thingo that writes a macro rather than VBA.

" I want to validate that the info
entered is not already in the table"

Isn't this something you would manage at table level using indexes and/or keys?  I would also suggest you use an unbound form as it is much easier to deal with these sorts of things as you can validate the data *before* it is written to the table.  To do this you can call up a recordset against your form data and if the recordcount  = 0 you know the record doesn't exist and can add it.  Other advantage is the user can painlessly exit the form without saving - fast and easy.  Of course the bound / unbound debate on this list get pretty heated from time to time and there are pros and cons to both approaches.

Anyway, a bit hard to give you the best answer as I don't fully understand what your data set up is.


Cheers
Darryl.

-----Original Message-----
From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of William Benson (VBACreations.Com)
Sent: Monday, 24 October 2011 1:17 PM
To: 'Access Developers discussion and problem solving'
Subject: [AccessD] AddNewRecord "Problem"

Accdb database, I am not too familiar with Ac2010.

... especially how Access creates embedded events and actions instead of
normal vba code to handle standard record operations on a buttonclick such
as New Record. So I am trying to use VBA.

When I create a new record in the table, I want to validate that the info
entered is not already in the table. I could probably do this in the
BeforeInsert, but I am instead doing it on the button click.

If the record is one which  may be added I want to insert a record. I am
doing this presently by setting a dao recordset equal to the form's
recordsetclone, and then saying Rst.AddNew, and then populating a few fields
which are not bound to controls, then using bookmark to bring the rest of
the form (and the bound controls) up to date and position the form on the
correct record.

That part is clunky but working, but the problem is that the Current event
is not firing. For that matter, the Addnew is not firing either.

I know I can call those events with code, but I was wondering why this
method is not causing Current to fire on its own when I set the form's
bookmark equal to the recordset's bookmark?

-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com






More information about the AccessD mailing list