Solved Form data enable/disabled (1 Viewer)

smtazulislam

Member
Local time
Today, 12:30
Joined
Mar 27, 2020
Messages
806
Hi,
I have an employee database where tblEmployee into field EmployeeID (PK) to relationship (FK) 8 tables and 8 forms.
And I have a table also tblStatus:
StatusID
- AutoN
Status- PK (this field is relationship with tblEmployee)
Data Record is
- 1. Active - 2. Final Exit - 3.Vacation - 4. Escape (Runaways) - 5. Police Custody.


So, I want if I select "cboStatus" 2. Final Exit - 4. Escape (Runaways) - 5. Police Custody from frmEmployee FORM then employees all data is Disabled within 8 forms. and if 1. Active - 3.Vacation - then data is Enable.

What I try :
Code:
Private Sub EnableData()
    txtEmployeeID.Enabled = true
    txtEmployeeName.Enabled = true
    alltxt.......=true
End Sub

Private Sub DisabledData()
    txtEmployeeID.Enabled = false
    txtEmployeeName.Enabled = false
    alltxt.....=false
End Sub

Private Sub cboStatus_Change()
    If (Me.cboStatus) = 2 Or 4 Or 5 Then
    DisabledData
    Else
    EnableData
    End If

End Sub

This method is worked. But when form reopen then all data is enable again.
Hope an expert pleasure to give advice .... How to do it once 8 forms.

Capture.JPG
Capture 1.JPG
 
Last edited:

June7

AWF VIP
Local time
Today, 01:30
Joined
Mar 9, 2014
Messages
5,423
Call procedure in form Current event.

Instead of VBA, consider using Conditional Formatting to enable/disable textbox or combobox.
 

smtazulislam

Member
Local time
Today, 12:30
Joined
Mar 27, 2020
Messages
806
Thank you June7 for reply. Now all field is disabled with 1. Active - 3.Vacation
if I try to change field but didnot enable.
here any mistake ....

Private Sub EnableData()
txtEmployeeID.Enabled = True
txtEmployeeName.Enabled = True
End Sub

Private Sub DisabledData()
txtEmployeeID.Enabled = False
txtEmployeeName.Enabled = False
End Sub

Private Sub Form_Current()
If (Me.cboStatus) = 2 Or 4 Or 5 Then
DisabledData
Else
EnableData
End If
End Sub
 

June7

AWF VIP
Local time
Today, 01:30
Joined
Mar 9, 2014
Messages
5,423
If you use Conditional Formatting, VBA should not be needed.

Your code could not have been working properly. Have to repeat the combobox for each parameter.

If Me.cboStatus = 2 Or Me.cboStatus =4 Or Me.cboStatus = 5 Then

Might also want to call procedure in cboStatus AfterUpdate event.

If you must use VBA, consider simplified code.

Code:
Private Sub EnableDisableData()
Me.txtEmployeeID.Enabled = Me.cboStatus = 2 Or Me.cboStatus = 4 Or Me.cboStatus = 5
Me.txtEmployeeName.Enabled = Me.cboStatus = 2 Or Me.cboStatus = 4 Or Me.cboStatus = 5
End Sub

Private Sub Form_Current()
EnableDisableData
End Sub

Private Sub cboStatus_AfterUpdate()
EnableDisableData
End Sub

Should txtEmployeeID always be Disabled or at least Locked? Are users allowed to edit this field?
 
Last edited:

smtazulislam

Member
Local time
Today, 12:30
Joined
Mar 27, 2020
Messages
806
Hey June7 , same happen,
All data disable and if change cboStatus then enable all. Is it possible in the query, HOW to ?
 

smtazulislam

Member
Local time
Today, 12:30
Joined
Mar 27, 2020
Messages
806
Hi I call Mr. arnelgp could you possible to help with this issue, Please I want to EmployeeID is Disabled with CboStatus selection once others relationship 8 forms also disabled. if VBA or Query anything can use.
 

isladogs

MVP / VIP
Local time
Today, 09:30
Joined
Jan 14, 2017
Messages
18,186
Thank you isladogs for your reply. I downloaded and checked. it was also reopen form then enable data. Not procedure keep as command.
And I needs EmployeeID is disabled into all of the relations form.
You can certainly do all of that using the Tag property. Suggest you study the code and adapt it accordingly for your purposes.
Good luck
 

June7

AWF VIP
Local time
Today, 01:30
Joined
Mar 9, 2014
Messages
5,423
What do you mean by "all" - every record? Yes, setting Enabled property will affect ALL instances of textbox, as can be seen if form is in Datasheet or Continuous view. If you want to enable/disable per record on Datasheet or Continuous form MUST use Conditional Formatting.

If "all" means all 8 forms then need code behind each form.

Conditional Formatting of textboxes and comboboxes would eliminate this VBA.
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 17:30
Joined
May 7, 2009
Messages
19,169
maybe something like this:
Code:
Private Sub EnableData()
    txtEmployeeID.Enabled = True
    txtEmployeeName.Enabled = True
    alltxt.......=true
End Sub

Private Sub DisabledData()
    txtEmployeeID.Enabled = False
    txtEmployeeName.Enabled = False
    alltxt.....=false
End Sub

Private Sub cboStatus_Change()
    If InStr("2;4;5", Me.cboStatus & "") > 0 Then
    DisabledData
    Else
    EnableData
    End If

End Sub

Private Sub Form_Current()
    Call cboStatus_Change
End Sub
 

smtazulislam

Member
Local time
Today, 12:30
Joined
Mar 27, 2020
Messages
806
maybe something like this:
.
Thank you so much for gave times, I really feels proud to see you this thread. I appreciate you.

When I change cboStatus then worked. but reopen it has not keep procedure event VBA
 

smtazulislam

Member
Local time
Today, 12:30
Joined
Mar 27, 2020
Messages
806
What do you mean by "all" - every record?
If "all" means all 8 forms then need code behind each form.

Hi June, thanks.
Yeah, I want 8 forms every records is disabled with a selected cbostatus .
in 8 forms [3 Single Form, 2 subform, 3 Continuous Forms ]
Is it possible ? Please help
 

June7

AWF VIP
Local time
Today, 01:30
Joined
Mar 9, 2014
Messages
5,423
Can enable/disable subform container control. Then no record in subform can be edited.
 

smtazulislam

Member
Local time
Today, 12:30
Joined
Mar 27, 2020
Messages
806
Can enable/disable subform container control. Then no record in subform can be edited.
actually, others form I dont try yet, I just try a SINGLE FORM which form I uploaded in first post messaged.
 

June7

AWF VIP
Local time
Today, 01:30
Joined
Mar 9, 2014
Messages
5,423
I am lost and confused. Not really understanding what you want to do. You have been provided many suggestions but your requirement is still not clear. Language barrier isn't helping.

If you want to provide db for analysis, follow instructions at bottom of my post.
 

smtazulislam

Member
Local time
Today, 12:30
Joined
Mar 27, 2020
Messages
806
Oh ! Mr. June, I want a method that when I selected CboStatus to Final Exit or Escape or Police Custody then EmployeeID within All relationship (any 8 Forms) data is disable.
is it clear now what I actually wanting ?
Please help me
 

smtazulislam

Member
Local time
Today, 12:30
Joined
Mar 27, 2020
Messages
806
details: I have 1324 recorded in my database including 24 tables, And 8 tables connection (relationship) to EmployeeID. There is ACTIVE Employees 622 only. some employee have in vacation.
So I need InActive employee data is disable in the form when open. because without read data I understand this employee are not more in the company.
Hope you understood my problem issue.
 

June7

AWF VIP
Local time
Today, 01:30
Joined
Mar 9, 2014
Messages
5,423
Again, you have been given guidance to accomplish that. Have you tried suggested code?

Is cboStatus sitting on main form? If yes, then code behind each subform:

If InStr("2;4;5", Me.Parent.cboStatus & "") > 0 Then

If you want more help, provide database.
 

Users who are viewing this thread

Top Bottom