[AccessD] AddNewRecord "Problem"

Darren - Active Billing darren at activebilling.com.au
Sun Oct 23 22:07:52 CDT 2011


Hi William,
I agree with Darryl, tricky to make a useful suggestion without know a bit
more.
Normally for this sort of stuff I do it in the Before Update and use a
DCOUNT or DLOOKUP, depending on the info.
Then, if the count is greater than one, or if the info exists, I present a
message box and cancel the sub.
Depending on what's being added, usually somewhere, there is something
pertinent that can be caught in a simple Domain Lookup.
You can have multi parameters in the DLOOKUP too, and if it's just one line
or one record to 'test' (i.e. No Loops) then the speeds are fine in my
experience. - e.g. (pseudo code for very simple application of adding a new
record)

If you are trying to insert an AccountNo that already exists then msgbox the
error and exit
intNoOfAccounts = DCount("[AccountNo]", "tblAccounts", " AccountNo = " &
Forms!frmSomeForm!txtSometextBox & " and IsCurrent = -1")

if intNoOfAccounts>=1 then
	Msgbox "Something here about there already being an active AccountNo
of  " & Forms!frmSomeForm!txtSometextBox
	Cancel = true
Else
	''bat on - good to go
Exit sub
 (Yes, I know you will all say that 'AccountNo' should be an indexed field
blah blah blah, - I agree - this is just for demonstration)
Hope this helps
Darren


-----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