Presence of Control

adickie

New member
Local time
Today, 00:38
Joined
Jan 28, 2003
Messages
9
Is there anyway to check if a particular control is on a form. I want to set something up like this:

If txtQuantity1 is present then
. . . .
ElseIf txtQuantity2 is present then
. . . .
End if

Is this possible?

Thanks
 
Do you mean check if there is data in the control? Presumably the controls will always be there.

If you're trying to see of there's data in a control you can use either

If IsNull(Me.txtQuantity1) then 'Check for Null value
...


or


If Nz(Me.txtQuantity1,"") = "" then 'Check for Null or zero-lengh string
...
 
Last edited:
Thanks Jim, but I need to check if a text box is actually present. What I have is 175 text boxes, one for each supply that can be ordered. I use code to loop through the text boxes and find which ones have a quantity in them. Here is that code:

For I = 1 To 175
If Me("txtSuppQty" & I).Enabled = True Then
If Me("txtSuppQty" & I) = "0" Then
Me("txtSuppQty" & I) = Null
End If
If Not IsNull(Me("txtSuppQty" & I)) Then
Set rs = db.OpenRecordset("SupplyRequestDetail", DB_OPEN_DYNASET)
rs.AddNew
rs("SupplyRequestID") = txtSupplyRequestID
rs("SupplyID") = Me("cboSuppID" & I)
rs("Quantity") = Me("txtSuppQty" & I)
rs.Update
rs.Close
End If
Else: Me("txtSuppQty" & I).Locked = False
Me("txtSuppQty" & I).Enabled = True
End If
Next I

As you can see I have assigned each of the text boxes names with ascending numbers in order to loop through them. The problem is if I remove one of the supplies and have to remove its corresponding text box then when I run the code it says is can't go on because txtSuppQty123 is missing. I need to add an if statment that says if txtSuppQty123 is not present skip it and go on to the next.

I hope this makes some snese.

Thanks for your help.
 
Sorry, I can't see that you have actually removed a text box control, only changed its locked/enabled status. Can't you just look at the locked/enabled state to see if it's "removed"? Maybe I'm missing something fundamental.
 
I'm making this too difficult. I can just change the values in the loop. If I take out number 123 I'll make the loop for I=1-122 and 124-175.

Thanks Jim.
 

Users who are viewing this thread

Back
Top Bottom