Main Form bound Textbox value Limits # of Subform Records

Oblio1963

New member
Local time
Today, 00:34
Joined
Sep 20, 2016
Messages
9
Hi,

Please see attached database.

There is a one to many relationship between t_Main and t_Sub.
A bound textbox on f_t_Main contains a number which is the total number of subform records there are allowed to be.

So, I am thinking that I would need some VBA Code such as:

Code:
Private Sub AllowedSubformRecords()
    Dim rst As Object
    Set rst = Me.RecordsetClone
    If rst.RecordCount >= Me.Parent.Controls_("Main_Form_Number") Then
        Me.AllowAdditions = False
    Else
        Me.AllowAdditions = True
    End If
End SubEnd Sub

I am calling this in the On Current Event of the Main Form, as well as the Subform On Current Event, and I am also calling it in the AfterDeleteConfirm, and AfterInsert.

Code:
If rst.RecordCount >= Me.Parent.Controls_("Main_Form_Number") Then

When trying to create a new record I get: Runtime Error 2465 Application-Defined or Object-Defined error and the above code line is highlighted

Also, I get a runtime error 2452 "the expression you entered has an invalid reference to the parent property"

If someone could please help with this I am trying to bake a cake based on some internet recipes and clearly I do not know how to fix this.........:(

Thank you for any help !!!!!!!!!!!
 

Attachments

It looks like you're checking to see if the record count is greater that a contol.
What control?
A better way is Me.txtBox.
Or forms!main!txtBox.

Rather ,it's,
Me.allowAdditions= recordcount>me.txtBox
 
I'm not sure if you meant to attach a new version as the version attached here does not allow any new main form records?
 
It looks like you're checking to see if the record count is greater that a contol.
What control?
A better way is Me.txtBox.
Or forms!main!txtBox.

Rather ,it's,
Me.allowAdditions= recordcount>me.txtBox

Thank you for your suggestion. I have made the following changes based on your suggestions:

Code:
Private Sub AllowedSubformRecords()

    Dim rst As Object
    Set rst = Me.RecordsetClone
    If Me.AllowAdditions = RecordCount >Forms!f_t_Main!Main_Form_Number Then
        Me.AllowAdditions = False
    Else
        Me.AllowAdditions = True
    End If
End Sub

Unfortunately, I cannot enter any new main form records. I even added a command button on the Main Form to add new records and it said I "cannot go to the specified record"...

Any ideas why?
 
Try it now, you had among other thing some syntax errors.

The attached database would not allow me to add new records and appeared to be the unchanged database?

Now if I try to download it, it keeps asking to save it as attachment.php?

Am I doing something wrong?
 
THANK YOU THANK YOU THANK YOU.... oh I have been banging my head against a wall for so long on this I cannot tell you how grateful I am !!!!! :)

Can I buy you a beverage ???
 
You're welcome, Cheers! :)
 

Users who are viewing this thread

Back
Top Bottom