PC Review


Reply
Thread Tools Rate Thread

How do I lock a sub form when a summary value has been reached?

 
 
Will_T
Guest
Posts: n/a
 
      7th Jul 2009

I have a subform that I need to lock when a fixed total of hours have
reached. Currently, I have a hidden text box on the subform that totals the
number of hours for a student. When the total number of hours for that
student reaches a fixed number I need to lock the subform were it will not
allow any new records to be added. The user may edit the records contained
in the subform but they cannot add.

Regarding the total number of hours, that value appears on the main form.

What would be the best way to do this?
--
Will
 
Reply With Quote
 
 
 
 
Jack Leach
Guest
Posts: n/a
 
      7th Jul 2009
Something like this....

If NumOfHours > MaxValue Then
Me.subformcontrol.Form.AllowAdditions = False
End If

There are also AllowEdits and AllowDeletions properties.

This might be of some use as well:
http://allenbrowne.com/ser-56.html

This will lock all of the controls, but still allow unbound controls to be
used. Might come in handy

hth


--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)



"Will_T" wrote:

> I have a subform that I need to lock when a fixed total of hours have
> reached. Currently, I have a hidden text box on the subform that totals the
> number of hours for a student. When the total number of hours for that
> student reaches a fixed number I need to lock the subform were it will not
> allow any new records to be added. The user may edit the records contained
> in the subform but they cannot add.
>
> Regarding the total number of hours, that value appears on the main form.
>
> What would be the best way to do this?
> --
> Will

 
Reply With Quote
 
John W. Vinson
Guest
Posts: n/a
 
      8th Jul 2009

On Tue, 7 Jul 2009 13:26:01 -0700, Will_T <(E-Mail Removed)>
wrote:

>I have a subform that I need to lock when a fixed total of hours have
>reached. Currently, I have a hidden text box on the subform that totals the
>number of hours for a student. When the total number of hours for that
>student reaches a fixed number I need to lock the subform were it will not
>allow any new records to be added. The user may edit the records contained
>in the subform but they cannot add.
>
>Regarding the total number of hours, that value appears on the main form.
>
>What would be the best way to do this?


I'd use the Form's BeforeInsert event to check. You don't need the hidden
textbox (though it is certainly ok if you have other uses for it); you could
use code like (assuming 8 hours is the limit)

Private Sub Form_BeforeInsert(Cancel as Integer)
If DSum("[Hours]", "[tablename]", "[StudentID] = " & Me!StudentID) _
>= 8 Then

MsgBox "This student has too many hours already", vbOKOnly
Cancel = True
End If
End Sub

You may want to instead (or in addition) put similar code in the hours
textbox's BeforeUpdate event, so if a student already has 6.5 hours, and
someone tries to add 2, you'ld prevent that entry.
--

John W. Vinson [MVP]
 
Reply With Quote
 
Will_T
Guest
Posts: n/a
 
      9th Jul 2009

I keep getting a 3464 Error, "Data type mismatch in criteria expression." I
have looked at my SSN fields of both the table and the subform and they are
both text fields. My Hours for both the table and the subform or both long
integer. My procedure is as follows;

Private Sub Form_BeforeInsert(Cancel As Integer)
If DSum("[Hours]", "[T_Communications]", "[SSN] = " & Me!SSN) > 9 Then
MsgBox "This student has too many hours already.", vbOKOnly
Cancel = True
End If
End Sub

What did I do wrong?

--
Will


"John W. Vinson" wrote:

> On Tue, 7 Jul 2009 13:26:01 -0700, Will_T <(E-Mail Removed)>
> wrote:
>
> >I have a subform that I need to lock when a fixed total of hours have
> >reached. Currently, I have a hidden text box on the subform that totals the
> >number of hours for a student. When the total number of hours for that
> >student reaches a fixed number I need to lock the subform were it will not
> >allow any new records to be added. The user may edit the records contained
> >in the subform but they cannot add.
> >
> >Regarding the total number of hours, that value appears on the main form.
> >
> >What would be the best way to do this?

>
> I'd use the Form's BeforeInsert event to check. You don't need the hidden
> textbox (though it is certainly ok if you have other uses for it); you could
> use code like (assuming 8 hours is the limit)
>
> Private Sub Form_BeforeInsert(Cancel as Integer)
> If DSum("[Hours]", "[tablename]", "[StudentID] = " & Me!StudentID) _
> >= 8 Then

> MsgBox "This student has too many hours already", vbOKOnly
> Cancel = True
> End If
> End Sub
>
> You may want to instead (or in addition) put similar code in the hours
> textbox's BeforeUpdate event, so if a student already has 6.5 hours, and
> someone tries to add 2, you'ld prevent that entry.
> --
>
> John W. Vinson [MVP]
>

 
Reply With Quote
 
John W. Vinson
Guest
Posts: n/a
 
      9th Jul 2009
On Thu, 9 Jul 2009 09:07:03 -0700, Will_T <(E-Mail Removed)>
wrote:

>I keep getting a 3464 Error, "Data type mismatch in criteria expression." I
>have looked at my SSN fields of both the table and the subform and they are
>both text fields. My Hours for both the table and the subform or both long
>integer. My procedure is as follows;
>
>Private Sub Form_BeforeInsert(Cancel As Integer)
> If DSum("[Hours]", "[T_Communications]", "[SSN] = " & Me!SSN) > 9 Then
> MsgBox "This student has too many hours already.", vbOKOnly
> Cancel = True
> End If
>End Sub
>
>What did I do wrong?


Left out the syntactically required quotemarks needed for Text fields. Try

DSum("[Hours]", "[T_Communications]", "[SSN] = '" & Me!SSN & "'")

Expanded for readability (don't do it this way!) that's

DSum("[Hours]", "[T_Communications]", "[SSN] = ' " & Me!SSN & " ' ")

to generate a search string like

[SSN] = '000-00-0000'

--

John W. Vinson [MVP]
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Making a summary form that will sum the values from another form a =?Utf-8?B?c2hlcGhlcmRlc3M=?= Microsoft Access Database Table Design 0 14th Aug 2007 02:10 PM
Summary on a form Alan T Microsoft Access Forms 1 4th Jun 2007 03:04 PM
Form Summary Fields Vs. Form Flickering =?Utf-8?B?U3ByaW5rcw==?= Microsoft Access Forms 0 2nd Mar 2006 03:26 PM
Lock Summary Properties =?Utf-8?B?TG9rZXNo?= Microsoft Excel Misc 1 13th Aug 2004 10:45 PM
Help With Form Summary Jen Microsoft Access Form Coding 1 24th Jul 2003 02:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:37 AM.