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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable control/field once if a value already exists

Status
Not open for further replies.

aaabuhalime

Instructor
Nov 22, 2012
67
US
Hi all,
This question is based on my questions in the past threads, I want to see how can I do the following, I want to be able to disable the "Wt1" filed in my form once a value entered in this field/ value exists for that student, so I want to continue using the following criteria,
CODE --> vb

Select Case Me.WhoIsIt
Case "Student"
Select Case Me.Status
Case "Active"
Wt1.Enabled = True
else
Wt1.Enabled = True

I want also to check if there is a value entered/exists in Wt1 field for that student, if yes then it disables Wt1 field, the value shows in the filed, I am trying the following code in the before update behind Wt1 field
CODE --> vb

Private Wt1_BeforeUpdate(Cancel As Integer)
Dim Check As Variant
Check = DLookup("[Wt1]", "queryxx", "[Wt1] = '" & Me.Wt1 & "'")
If Not IsNull(Check) Then
Me.Wt1.Enabled=True
else
Me.Wt1.Enabled=False

End If
End Sub

I know I am missing something, I cant figure out how to link the three condition together, studentID, and Status, and if the value exists.Can use While statement?if not what would be the best way to achieve my goal.

Any help will be appreciated.
 

I should think something like the following would be a more appropriate criteria for DLookup since you appear to be looking for a value related to a specific student.

Check = DLookup("[Wt1]", "queryxx", "[StudentID] = " & Me!StudentID)

I'm really unclear on what you are trying to accomplish. If you are disabling a control to prevent the user from changing the control's value, then why wait until the user has already made the changes? The form's load event seems a better choice.

Also, to disable a control, I believe you will have to first move the focus.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top