Procedure (1 Viewer)

linskill

Registered User.
Local time
Today, 15:34
Joined
Nov 1, 2012
Messages
38
Its been over 10 years since I last used Access. My employer has enticed me into getting back in the saddle and I must admit I am enjoying myself even if my memory keeps reminding me that I am getting old...
What is the best way of ensuring a user selects a customer before they attempt to open a subform.
Thanks
 

Gasman

Enthusiastic Amateur
Local time
Today, 15:34
Joined
Sep 21, 2011
Messages
14,362
Disable the method of opening the subform until a customer value is entered?
 

plog

Banishment Pending
Local time
Today, 09:34
Joined
May 11, 2011
Messages
11,657
No subform, 2 forms.

First form they select a customer from a drop down and click a button. Second form opens from first, loads customer data in the header and the detail section is all the data that would have been on the subform.
 

linskill

Registered User.
Local time
Today, 15:34
Joined
Nov 1, 2012
Messages
38
No subform, 2 forms.

First form they select a customer from a drop down and click a button. Second form opens from first, loads customer data in the header and the detail section is all the data that would have been on the subform.
Thanks, It is looking like two forms is the way forward.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 10:34
Joined
Feb 19, 2002
Messages
43,368
In the subform's BeforeInsert event, check that the PK in the main form is populated.
Code:
If Me.Parent.txtPrimaryKey & "" = "" Then
    Msgbox "Please create a Client record first.", vbOKOnly
    Me.Parent.txtPrimaryKey.SetFocus
    Cancel = True
    Me.Undo
    Exit Sub
End If

REMEMBER - simply setting focus into the Subform will force the main form record to be saved. So, as long as the PK in the mainform is not empty, there is a valid parent record and so a subform record may be added.

I actually think that newer versions of Access are now performing this validation for you but if not, the BeforeInsert event is your friend. It runs only for a new record and it runs as soon as the user has typed a single character into a control on the subform.
 

Users who are viewing this thread

Top Bottom