A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Sub form question



 
 
Thread Tools Display Modes
  #1  
Old April 15th, 2008, 08:42 PM posted to microsoft.public.access.forms
Question Boy[_2_]
external usenet poster
 
Posts: 179
Default Sub form question

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
  #2  
Old April 15th, 2008, 09:24 PM posted to microsoft.public.access.forms
Dirk Goldgar
external usenet poster
 
Posts: 1,164
Default Sub form question

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 the

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

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


"Question Boy" wrote:

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

  #3  
Old April 15th, 2008, 09:52 PM posted to microsoft.public.access.forms
Question Boy[_2_]
external usenet poster
 
Posts: 179
Default Sub form question

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



"Dirk Goldgar" wrote:

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 the

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

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


"Question Boy" wrote:

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

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 12:53 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.