How to control adding new record in Datasheet view

usermj

Registered User.
Local time
Today, 03:00
Joined
Dec 12, 2004
Messages
39
Hi there,

I designed a form which contains a combox and SubForm (in DataSheet view).
The combox allows users to select the number of record they want to append. The subform (in DataSheet view) will automatically control the number of records users can entry.

Normally, in DataSheet view, if click the enter, the system will automatically swap to the next line and add a new record in the related table.

So , is there any chance I can use programming to control it? If the number of records has reached the number user chose prievously, the system will not append any more record even clicking the enter or using new record function.

!!! Be aware it should be in the DataSheet view.

Many Thanks
 
I'm sorry I probably won't be too helpful, but it seems that this shouldn't be too hard. I would think that this could go into code on the form's back end.

It might go in the form current, or before insert. You might have to play with where to put it.

I would put some code that would be something like this:

Code:
If DCount("*", "tablenameofsubform", "subtableid = mainformlinkid") = [#maxnumberofrecords#] Then

Dim Msg, Style, Title
    Msg = "You may not add anymore records"
    Style = vbOK
    Title = "Max entries reached"

docmd.cancelevent ( or undo, something like that)

I know this is vague, but it might head you in the right direction. :D
 

Users who are viewing this thread

Back
Top Bottom