Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enable Or not , that is the question

Status
Not open for further replies.

dominicgingras

Technical User
Jul 15, 2002
53
CA
I have a form that I use to do my order entry. When the order is complete, I want to disable some of the sub-form.

So far I have use something like that

Private Sub Form_Current()

If [Status] = "Invoiced" Then
ReadOnly = "Read Only"
InvoiceButton.Enabled = False

Me.AllowEdits = False
[Forms]![WorkOrder].[TasksSubform].Form.AllowEdits = False
[Forms]![WorkOrder].[BillingDetailsSubform].Form.AllowEdits = False
[Forms]![WorkOrder].[NoteSubform].Form.AllowEdits = False
[Forms]![WorkOrder].[SchedulingSubform].Form.AllowEdits = False


End If

If [Status] = "Ordered" Then
ReadOnly = ""
Me.AllowEdits = True
[Forms]![WorkOrder].[TasksSubform].Form.AllowEdits = True
[Forms]![WorkOrder].[BillingDetailsSubform].Form.AllowEdits = True
[Forms]![WorkOrder].[NoteSubform].Form.AllowEdits = True
[Forms]![WorkOrder].[SchedulingSubform].Form.AllowEdits = True

InvoiceButton.Enabled = True
End If

If [Status] = "Pending" Then
ReadOnly = ""
Me.AllowEdits = True
[Forms]![WorkOrder].[TasksSubform].Form.AllowEdits = True
[Forms]![WorkOrder].[BillingDetailsSubform].Form.AllowEdits = True
[Forms]![WorkOrder].[NoteSubform].Form.AllowEdits = True
[Forms]![WorkOrder].[SchedulingSubform].Form.AllowEdits = True


InvoiceButton.Enabled = False
End If
End Sub


As you can see this is very long.


Also I get a problem if my user press a button on the form that display a list box with some choice, when he go back to the from, It is not disable anymore

This is probably not the right method for doing this.

Any idea?
 
Hi there

Your code isn't long. Since you're only disabling when [Status] = Invoice and there are no combinations of enabled/disabled, you could shorten your code slightly, e.g.:
[tt]
Private Sub Form_Current()
Dim flgReadWrite as boolean

'Check status of form
if [Status] = "Invoiced" then
flgReadWrite = False
ReadOnly = "Read Only"

else
flgReadOnly = True
ReadOnly = ""

end if

'Change edit status of controls
InvoiceButton.Enabled = flgReadWrite
Me.AllowEdits = flgReadWrite
[Forms]![WorkOrder].[TasksSubform].Form.AllowEdits = flgReadWrite
[Forms]![WorkOrder].[BillingDetailsSubform].Form.AllowEdits = flgReadWrite
[Forms]![WorkOrder].[NoteSubform].Form.AllowEdits = flgReadWrite
[Forms]![WorkOrder].[SchedulingSubform].Form.AllowEdits = flgReadWrite

End Sub
[/tt]

I can't think why the 'edit' status of the form changing when the user opens another form...what does the popup form with the listbox do?

Cheers,
Dan
 
Opps, I missed the InvoiceButton...

[tt]
Private Sub Form_Current()
Dim flgReadWrite as boolean

'Check status of form
Select case [Status]
case "invoiced"
flgReadWrite = false
ReadOnly ="Read Only"
InvoiceButton.Enabled = False

case "Ordered"
flgReadWrite = true
ReadOnly =""
InvoiceButton.Enabled = true

case "Pending"
flgReadWrite = true
ReadOnly ="Read Only"
InvoiceButton.Enabled = false

End Select

'Change edit status of controls
Me.AllowEdits = flgReadWrite
[Forms]![WorkOrder].[TasksSubform].Form.AllowEdits = flgReadWrite
[Forms]![WorkOrder].[BillingDetailsSubform].Form.AllowEdits = flgReadWrite
[Forms]![WorkOrder].[NoteSubform].Form.AllowEdits = flgReadWrite
[Forms]![WorkOrder].[SchedulingSubform].Form.AllowEdits = flgReadWrite

End Sub
[/tt]
 
Hi there, I would add a watch expression and check when the 'allowedits' property changes from false to true. You could call the form_current event from the form_activate event (and also check the [status] value).

Cheers,
Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top