Sub-form code not working as I intended

  • Thread starter Thread starter CB
  • Start date Start date
C

CB

Hi everyone,

I have a question regarding the following code that I’ve placed in the
current event of a sub-form. Clearly, I’m misunderstanding something. A
little background first…

A parent record (i.e., Quote Request) selected on the main form can be
linked to one or more child records (i.e. Work Order submissions) on the
subform. My intention was that depending on the value of “txtWOStatus,â€
certain fields would be locked ONLY FOR THOSE PARTICULAR CHILD RECORDS. For
example, if a work order was accepted, I’m trying to prevent the user from
adding another work order to the Quote Request selected on the main form.

What is happening is that when I select a different parent record on the
main form, certain cells are locked based on the value of “txtWOStatus†in
the previous child record I looked at. I hope I explained that clearly enough!

What am I missing?

Thanks for any and all suggestions!

Chris

Private Sub Form_Current()

Select Case Me.txtWOStatus
Case "Amendment Requested"
Me.txtWOCompDate.Locked = True
Me.txtWOActAmt.Locked = True
Me.txtWOActLink.Locked = True
MsgBox ("You cannot enter completion information on this record
as an amendment was requested." & vbCrLf & _
"Enter the information on the record where the word order
was Accepted.")
Case "Accepted"
Me.txtWONum.Locked = True
Me.txtWONumRev.Locked = True
Me.txtWODate.Locked = True
Me.txtWOEstAmt.Locked = True
Me.txtWOStatus.Locked = True
Me.txtWOComment.Locked = True
Me.txtSMID.Locked = True
Me.txtWOCompDate.Locked = True
Me.txtWOActAmt.Locked = True
Me.txtWOActLink.Locked = True
MsgBox ("You cannot add another work order to this quote number
as the last work order was accepted.")
Case "Rejected"
Me.txtWOCompDate.Locked = True
Me.txtWOActAmt.Locked = True
Me.txtWOActLink.Locked = True
End Select

End Sub
 
CB said:
Hi everyone,

I have a question regarding the following code that I’ve placed in the
current event of a sub-form. Clearly, I’m misunderstanding something. A
little background first…

A parent record (i.e., Quote Request) selected on the main form can be
linked to one or more child records (i.e. Work Order submissions) on the
subform. My intention was that depending on the value of “txtWOStatus,â€
certain fields would be locked ONLY FOR THOSE PARTICULAR CHILD RECORDS.
For
example, if a work order was accepted, I’m trying to prevent the user from
adding another work order to the Quote Request selected on the main form.

What is happening is that when I select a different parent record on the
main form, certain cells are locked based on the value of “txtWOStatus†in
the previous child record I looked at. I hope I explained that clearly
enough!

What am I missing?

Thanks for any and all suggestions!

Chris

Private Sub Form_Current()

Select Case Me.txtWOStatus
Case "Amendment Requested"
Me.txtWOCompDate.Locked = True
Me.txtWOActAmt.Locked = True
Me.txtWOActLink.Locked = True
MsgBox ("You cannot enter completion information on this record
as an amendment was requested." & vbCrLf & _
"Enter the information on the record where the word order
was Accepted.")
Case "Accepted"
Me.txtWONum.Locked = True
Me.txtWONumRev.Locked = True
Me.txtWODate.Locked = True
Me.txtWOEstAmt.Locked = True
Me.txtWOStatus.Locked = True
Me.txtWOComment.Locked = True
Me.txtSMID.Locked = True
Me.txtWOCompDate.Locked = True
Me.txtWOActAmt.Locked = True
Me.txtWOActLink.Locked = True
MsgBox ("You cannot add another work order to this quote number
as the last work order was accepted.")
Case "Rejected"
Me.txtWOCompDate.Locked = True
Me.txtWOActAmt.Locked = True
Me.txtWOActLink.Locked = True
End Select

End Sub


I believe the problem is that your code never *unlocks* any of the controls.
For each record, you must lock the controls that should be locked and unlock
the controls that should not be locked. Otherwise, all the controls will
eventually be locked.
 
Thanks Dirk,

I **THINK** I have it working okay. I'll post back if I further issues.

Chris
 
Back
Top