Limts

  • Thread starter Thread starter C#''er
  • Start date Start date
C

C#''er

If I would like to limit the amount of times a user can enter a specific
value in a column....how would I do that. For example: I have a form linked
to a table. The table has a column called "Testing Sessions". The form gives
you the option to select testing sessions A, B, C, or D. I want it so once
you have selected session A 10 times, you can no longer select A. How can I
do this in Access?
 
If I would like to limit the amount of times a user can enter a specific
value in a column....how would I do that. For example: I have a form linked
to a table. The table has a column called "Testing Sessions". The form gives
you the option to select testing sessions A, B, C, or D. I want it so once
you have selected session A 10 times, you can no longer select A. How canI
do this in Access?

Check the existing count (you can use DCount) in the beforeInsert
event on your form, and if you've hit the limit, cancel the insert.

Cancel=(DCount()>=intLIMIT)
 
in the form, in the control's BeforeUpdate event, try

If DCount(1, "TableName", "[Testing Sessions] = '" _
& Me!ControlName & "'") > 9 Then
Cancel = True
MsgBox "This session is no longer available."
End If

replace TableName with the correct name of the table, and ControlName with
the correct name of the control, and note the brackets around the fieldname
Testing Sessions, necessary because of the embedded space in the name. you
shouldn't use spaces or special characters (other than underscore _ ) in
anything *you* name in Access. for more information, see
http://home.att.net/~california.db/tips.html#aTip5.

hth
 
Thanks Tina. But will ControlName be the name of the testing session? And
what does the 1 in the first parameter of the DCount method mean? The psuedo
code for what I am attepting goes something like this:

int testingSessionA;

if(testingSession.text == A)
{
testingSessionA++;
}

if(testingSessionA > 9)
{
MessageBox.Show("This session has been filled);
}

I can understand you code a little, but I dont know exactly where I would
put the "A" so I could keep count of how many times "A" has been used
tina said:
in the form, in the control's BeforeUpdate event, try

If DCount(1, "TableName", "[Testing Sessions] = '" _
& Me!ControlName & "'") > 9 Then
Cancel = True
MsgBox "This session is no longer available."
End If

replace TableName with the correct name of the table, and ControlName with
the correct name of the control, and note the brackets around the fieldname
Testing Sessions, necessary because of the embedded space in the name. you
shouldn't use spaces or special characters (other than underscore _ ) in
anything *you* name in Access. for more information, see
http://home.att.net/~california.db/tips.html#aTip5.

hth


C#''er said:
If I would like to limit the amount of times a user can enter a specific
value in a column....how would I do that. For example: I have a form linked
to a table. The table has a column called "Testing Sessions". The form gives
you the option to select testing sessions A, B, C, or D. I want it so once
you have selected session A 10 times, you can no longer select A. How can I
do this in Access?
 
I have a form linked
to a table. The table has a column called "Testing Sessions".
The form gives
you the option to select testing sessions A, B, C, or D.

so you have a table with a field named Testing Sessions. the table is bound
to a form. the form gives the user the option to select A, B, C, or D. i
take that to mean that the form has a combobox control, or perhaps a listbox
control, bound to field Testing Sessions. and this control offers four
options for data entry: A, B, C, or D. so in each record entered in the
form, the user can enter one of those four values in the control bound to
field Testing Sessions. and you want to count how many records already exist
in the table that have *whatever session letter* the user selects in the
control.

if all of the above is correct, then that control (combo, listbox, whatever
it is) has a name. in the code i posted, replace ControlName with *that
name*. if the above assumptions are not correct, then you'll need to explain
your setup in more detail.

as for the 1 in the DCount() function, it's just a simple way to count, as
each record that meets the criteria will return a 1, so if 5 records meet
the criteria, then counting 1, 1, 1, 1, 1 will equal 5.

hth


C#''er said:
Thanks Tina. But will ControlName be the name of the testing session? And
what does the 1 in the first parameter of the DCount method mean? The psuedo
code for what I am attepting goes something like this:

int testingSessionA;

if(testingSession.text == A)
{
testingSessionA++;
}

if(testingSessionA > 9)
{
MessageBox.Show("This session has been filled);
}

I can understand you code a little, but I dont know exactly where I would
put the "A" so I could keep count of how many times "A" has been used
tina said:
in the form, in the control's BeforeUpdate event, try

If DCount(1, "TableName", "[Testing Sessions] = '" _
& Me!ControlName & "'") > 9 Then
Cancel = True
MsgBox "This session is no longer available."
End If

replace TableName with the correct name of the table, and ControlName with
the correct name of the control, and note the brackets around the fieldname
Testing Sessions, necessary because of the embedded space in the name. you
shouldn't use spaces or special characters (other than underscore _ ) in
anything *you* name in Access. for more information, see
http://home.att.net/~california.db/tips.html#aTip5.

hth


C#''er said:
If I would like to limit the amount of times a user can enter a specific
value in a column....how would I do that. For example: I have a form linked
to a table. The table has a column called "Testing Sessions". The form gives
you the option to select testing sessions A, B, C, or D. I want it so once
you have selected session A 10 times, you can no longer select A. How
can
I
do this in Access?
 
Back
Top