Solved

Access 2007 Database

Posted on 2013-11-21
4
227 Views
Last Modified: 2013-12-02
Database consist of a form with a couple of tabbed subforms.  The main form has the primary key and date which is displayed and entered at the very top of the form.  Is there a way to not allow the user to input anything in the subform/body until the primary key field has been autopopulated.   This was prompted due to testing...where the entire form was populated with data, but the PK field never populated and resulted in a unbound record.  Thanks in advance for your help.
0
Comment
Question by:EASCOA
  • 2
4 Comments
 
LVL 61

Expert Comment

by:mbizup
Comment Utility
Are you using an auto number or a custom PK field?
0
 

Author Comment

by:EASCOA
Comment Utility
I guess it might be a custom PK--the department to identify their records...the primary key is set to start with "ST "000000000
0
 
LVL 61

Accepted Solution

by:
mbizup earned 300 total points
Comment Utility
Those custom numbers are usually triggerd by data entry in some required fields... so there are a couple of different approaches.

1.  Ensure that whatever field triggers the creation of your custom number has data in it before allowing the user to enter data in the subform.

In the Enter Event of the subform (main forms design):
if me.Requiredfield & "" = "" then 
msgbox "enter required data"
me.Requiredfield.setfocus
end if

Open in new window


OR

2.  Force the procedure that creates your custom number to run if the PK is blank/null:

if me.PK & "" = "" then 
   Call NameOfProcedureThatCreatesPK
   Me.Refresh
end if

Open in new window


Thats the general idea... but I can't get more specific without seeing how your database actually works.
0
 
LVL 34

Assisted Solution

by:PatHartman
PatHartman earned 200 total points
Comment Utility
If you are generating the ID rather than using an autonumber, code in the mainform's BeforeUpdate event should validate its presence.

In the subform, use the on Dirty event.   Check to see if the ID control on the main form is populated.  Doesn't matter if it is an autonumber or user-generated.  If it is not present, cancel the event, undo the update, and move focus back to the main form.

If IsNull(Me.Parent!yourID) Then
    Cancel = True
    Me.Undo
    Me.Parent!somecontrol.SetFocus
    Msgbox "some message", vbOKOnly
    Exit Sub
End If 

Open in new window

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now