Enable Disable field if value exist in it

zonexs123

Registered User.
Local time
Today, 22:32
Joined
Feb 6, 2011
Messages
39
Hi,

I have a very simple problem which I'm unable to figure it out in VBA. I know it would be easier for you all.

Well I have a form where there are numbers of fields. Now what my senior want it that whenever form load any field which having data (value) in it, disabled it to stop editing.

For Example:

Field1(Text box): 01/01/2012
Field2(Text box):
Field3(Text box):

Now, when form load it should allow user to access "Field2" & "Field3" however "Field1" should be visible in read only mode.


Please Advise.
 
Code:
me.txtTextBox.enabled = false

Will keep the control visible on the form but not allow any changes to it

Code:
me.txtTextBox.enabled = true

Re-enables the control and allows you to do stuff(tm) with it.
 
Appreciate your prompt reply but my problem still not solved. I know the above method however confuse where to add this. Here is my code:

Private Sub Form_Open(Cancel As Integer)
DoCmd.Maximize
Text452.SetFocus
If Me.Text360 = "" Then
Text360.Enabled = True
Else
Text360.Enabled = False
Exit Sub
End If
If Me.Text362 = "" Then
Text362.Enabled = True
Else
Text362.Enabled = False
Exit Sub
End If
If Me.Text364 = "" Then
Text364.Enabled = True
Else
Text364.Enabled = False
Exit Sub
End If
End Sub

Accordingly I have more than 10 textbox for which I have to add the feature where if data is not there then enabled the field else disabled.
 
when you use .Enabled = False user won't even be able to go into this field (for copying text for example).
Also field will be dimmed.

it's better to use .Locked = True

"" is not the same as null
you sould check for IsNull(Me.TextBox)
 
Thanks Smig !!! your advice worked now !!! but how can I apply to all of my textboxes. its more than 10. Should I have to code for each fields ??
like:

If IsNull(Me.Text360) Then
Text360.Locked = False
Else
Text360.Locked = True
End If


Any shorter process to do so.....
 
Since you do a boolean comparison you can do it in one line

ex:

Me.Text360.Locked = Not Isnull(Me.Text360)

You use the Not operator to reverse IsNull() test from True to False and False to True

JR
 
Thanks a lot.... work like charm :) Need one more help from you experts :) if you can.
As my fields are locked if value exist, can I highlight these fields in some color so user can identify these are not editable and are in read only mode.

Once again you all are great and appericate your support :)
 
when you use .Enabled = False user won't even be able to go into this field (for copying text for example).
Also field will be dimmed.

it's better to use .Locked = True

"" is not the same as null
you sould check for IsNull(Me.TextBox)

Thanks Smig, somehow the .locked property passed me by.
 
Thanks a lot.... work like charm :) Need one more help from you experts :) if you can.
As my fields are locked if value exist, can I highlight these fields in some color so user can identify these are not editable and are in read only mode.

Once again you all are great and appericate your support :)

if me.TextBox.Locked = True then
Me.TextBox.BackColor = WhateverColorYouWant
end if

Do you need to do it for all your fields one by one?
This depand if you check this for all your TextBox on form, are they named so you can identify them by 1, 2, 3, 4...

One note: this all is only good for a single record form, Not for continous form
 

Users who are viewing this thread

Back
Top Bottom