Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 MS Access
 anyway to loop this?

Author  Topic 

chobo
Starting Member

11 Posts

Posted - 2004-04-03 : 04:11:38
I have to check a lot of textboxes to see see if there is any text typed into them. The way I am doing it right now creates a lot of code. Ex

If IsNull(txtFirstName.Value) Then
MsgBox "Enter a firstname"
End If

That would be for one textbox. Is there a way to create a loop so I reduce my code?

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2004-04-03 : 10:58:49
two ways:

1) if you are not using the Tag property on the controls, set the property equal to a message or some indicator that this textbox needs to be not null. then, when you need to check all text boxes:

dim c as control
for each c in me.controls
if c.tag <> "" then
if IsNull(c.value) then
msgbox "Missing data: " & c.tag, vberror, "Missing Data"
' cancel the action here
exit sub
end if
end if
next
' if you get here, it's all OK


the Tag property is really useful for stuff like this.

or

2) create a collection of the controls you need to validate, maybe on the "Form Load" event, and enumerate that collection with a For-Each-Next loop when it's time to check them out:

for each c in YourCollectionOfControls
if Isnull(C.value) then
....
end if
next

actually, there's a lot more than just 2 ways, but that's a couple of ideas ...

- Jeff
Go to Top of Page
   

- Advertisement -