Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms / April 2008

Tip: Looking for answers? Try searching our database.

Sub form question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Question Boy - 15 Apr 2008 20:42 GMT
I have a form with a sub-form.

I only want the user to be able to enter one record (never more).  How can I
limit it.  Right now I'm having issues because the users accidentally tab
through the form onto another record and make duplicate/triplicate/...
entries.

Thank you,

QB
Dirk Goldgar - 15 Apr 2008 21:24 GMT
Am I right in understanding that you want to limit the records on the
subform, not the main form?  You can do this with a combination of code in
the subform and the main form.

In the code module of the form object that is being displayed as the
subform, add this function in the General section:

'----- start of public function code for subform -----
Public Sub LimitRecords()

   Const conRecLimit = 1

   With Me.RecordsetClone
       If .RecordCount > 0 Then .MoveLast
       Me.AllowAdditions = (.RecordCount < conRecLimit)
   End With

End Sub
'----- end of public function code for subform -----

Then create an event procedure for the Current event of that form, and call
the above function from there:

'----- start of code for subform's Current event -----
Private Sub Form_Current()

   LimitRecords
   
End Sub
'----- end of code for subform's Current event -----

In the Current event of the *main* form, you must also call the LimitRecords
function on the subform:

'----- start of code for main form's Current event -----
Private Sub Form_Current()

   Call Me.YourSubformControlName.Form.LimitRecords
   
End Sub
'----- end of code for main form's Current event -----

In the above, replace "YourSubformControlName" with the name of the subform
control name;  that is, the control on the main form that is displaying the
subform.

Signature

Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

> I have a form with a sub-form.
>
[quoted text clipped - 6 lines]
>
> QB
Question Boy - 15 Apr 2008 21:52 GMT
Worked like a charm!

But I do have a little question.  I understand the code for the sub-form,
but why the code in the parent form?

QB

> Am I right in understanding that you want to limit the records on the
> subform, not the main form?  You can do this with a combination of code in
[quoted text clipped - 52 lines]
> >
> > QB
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.