473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

VBA/Access: How do I "abandon" a record when using linked forms?

Hi I have a slight problem in trying to set up 2 forms linked to
tables.

What I want to do is to inform a control on one form(Apps)
as to the value of a key of a 'new' record entered via a
second(Clients)

In opening the second form I set up certian fields and controls
on it from the first. In doing so however this seemingly creates a
headache in coding for a situation where a user wants to abandon
entry of a new 'client', for example a NewClient button on the first
being selected by mistake for example.

If I set the Cancel in respect of the BeforeUpdate on the clients form
in the event of null fields, my current code will keep the cleints
form on the 'new' record, and will seemingly not allow an 'abort'
or move to another record. If I don't set the Cancel the Update will
quite happily insert 'blank' data into the database as part of the
update.

A related problem is to do with key allocation.
If having setup a 'new' client by means of opening the clients
form, the user abandons entry of that new client, I would ideally
like to reclaim the key allocated. I had previosuly been using
AutoNumbers but in abandoning records the AutoNumber concerned seemed
quite happy to advance even when a record had been abandoned..

So how do I code the various event routines for the form so that I can
both
setup controls/fields on the Clients form from the Applications form ,
avoid
'blank' records going into the database and have some method for
allocating,
deallocating key values?

(The current portions of code in respect of the forms concerned are
below)

FMNT80

Apps_Form:
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "Form_Apps"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Compare Database

Private Sub cmd_new_Click()
On Error GoTo Err_cmd_new_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Client"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms.Item(stDocName).donewentry Me.Form.Name, cmb_client.Name
Forms.Item(stDocName).Controls.Item("cmb_type") = 3
Exit_cmd_new_Click:
Exit Sub

Err_cmd_new_Click:
MsgBox Err.Description
Resume Exit_cmd_new_Click

End Sub

<ENDS>
Clients Form:
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "Form_Client"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Compare Database
Dim newentry As Boolean
Dim cbForm As String
Dim cbControl As String
Dim alloc As Integer

Public Sub donewentry(cbF As String, cbC As String)
cbForm = cbF
cbControl = cbC
newentry = True
If Not newrec Then DoCmd.GoToRecord , , acNewRec
End Sub

Private Sub cmb_type_BeforeUpdate(Cancel As Integer)
If Not IsNull Then
If abandon = True Then abandon = False
End If
End Sub

Private Sub cmd_close_Click()
On Error GoTo Err_cmd_close_Click
DoCmd.Close

Exit_cmd_close_Click:
Exit Sub

Err_cmd_close_Click:
MsgBox Err.Description
Resume Exit_cmd_close_Click
End Sub

Private Sub Form_AfterInsert()
If newentry Then
abandon = False
Forms.Item(cbForm).Controls.Item(cbControl).Value = txt_id
doexit
End If
End Sub

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(txt_name) And Not abandon Then
Cancel = True
abandon = True
alloc = alloc - 1
Form_Current
ElseIf abandon Then
Cancel = False
SendKeys ("{ESC}{ESC}")
If newentry Then doexit
End If
End Sub

Private Sub doexit()
On Error GoTo exit_err
DoCmd.Close acForm, Me.Form.Name

exit_exit:
Exit Sub

exit_err:
If Err.Number = 2501 Then
Debug.Print "2501"
Else
MsgBox Err.Number
End If
Resume exit_exit
End Sub

Private Sub Form_Current()
If Form.NewRecord Then
newrec = True
Me![txt_id] = alloc
alloc = alloc + 1
Else
newrec = False
If abandon Then
abandon = False
End If
End If

End Sub

Private Sub Form_Error(DataErr As Integer, Response As Integer)
If DataErr = 2501 Then Debug.Print "Ignored 2501"
Response = acDataErrContinue
End Sub

Private Sub Form_Load()
Rem Note alloc only set to 10 here as an example
Rem In reality the allocation of a key needs to be done in
Form_Current?

alloc = 10 :
newentry = False
End Sub

Private Sub Form_Unload(uCancel As Integer)
If newentry And abandon Then
If MsgBox("Abandon?", vbYesNo) = vbNo Then
uCancel = True
End If
End If
End Sub

<ENDS>
Nov 13 '05 #1
0 1893

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

63
by: Jerome | last post by:
Hi, I'm a bit confused ... when would I rather write an database application using MS Access and Visual Basic and when (and why) would I rather write it using Visual Studio .Net? Is it as easy...
3
by: Iain Miller | last post by:
I'm sure this ought to be simple but I can't make it work!! I have a form (based on a query) that holds information about an individual. Each individual has a Unique reference field called...
3
by: Colleyville Alan | last post by:
I am constructing a SQL command from a function. Some code builds the WHERE clause in a looping structure and passes that as an argument to the SQL-building function. But the results do not...
0
by: Privacy Trap | last post by:
Hi I have a slight problem in trying to set up 2 forms linked to tables. What I want to do is to inform a control on one form(Apps) as to the value of a key of a 'new' record entered via a...
11
by: olle | last post by:
Hi everyone. I am an Access developer having worked with Access-dev. projects for many years on Sql server databases and Access. For the internet I have been using traditional asp. But now I have...
55
by: AnandaSim | last post by:
I just had a google through this NG but have not seen mention of Erik Rucker's blog entry and the new Jet: http://blogs.msdn.com/access/archive/2005/10/05/477549.aspx mentioned by Mike...
6
by: Mike | last post by:
There is not going to be such a thing as "remoting" 2 years from now. I still see people working with it, and I wonder why they are not keeping up. Windows Communication Foundatoin, aka .Net...
3
prn
by: prn | last post by:
Hi folks, I've got something that's driving me crazy here. If you don't want to read a long explanation, this is not the post for you. My problematic Access app is a DB for keeping track of...
1
by: Dilruba | last post by:
I want the suggestion what is better for use between Session.abandon & Session.Contents.Remove
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.