Validate visible fields only.

J

juxey2000

Hi there.

I have a form which is effectively 4 forms in one. Depending on which buttons
you press, various firlds become visible or not visible and disabled
depending on whether they are required for that particular incident.

I would like to validate the form for null values before submitting and I
have tried this validation loop.

dim myObject as object
dim myCollection as collection

For Each myObject in myCollection
If isNull(myObject.Value) Then
Msgbox("Field can not be null, bla bla bla")
myObject.setFocus
end if
Next

However, I only want it to check for null values in visible/enabled fields
only. I have tried playing around with the code but I'm not that good with
VBA. I'm hoping it's an easy answer.

Cheers.
 
K

Ken Snell

For Each myObject in myCollection
If isNull(myObject.Value) And myObject.Visible = True Then
Msgbox("Field can not be null, bla bla bla")
myObject.setFocus
end if
Next
 
J

juxey2000

I'm really sorry.

that was my old code which wouldn't work.

I'm currently using.

dim myObject as object
dim myCollection as collection

For Each myObject in myCollection
If isNull(myObject.Value) Then
Msgbox("Field can not be null, bla bla bla")
myObject.setFocus
end if
Next

Sorry, hope you can still help.

Cheers

Ken said:
For Each myObject in myCollection
If isNull(myObject.Value) And myObject.Visible = True Then
Msgbox("Field can not be null, bla bla bla")
myObject.setFocus
end if
Next
Hi there.
[quoted text clipped - 22 lines]
 
K

Ken Snell

So, how are you filling the myCollection object? What does it contain? What
properties does each object in that collection have?

The code I provided will work if you cycle through controls.
--

Ken Snell
http://www.accessmvp.com/KDSnell/



juxey2000 said:
I'm really sorry.

that was my old code which wouldn't work.

I'm currently using.

dim myObject as object
dim myCollection as collection

For Each myObject in myCollection
If isNull(myObject.Value) Then
Msgbox("Field can not be null, bla bla bla")
myObject.setFocus
end if
Next

Sorry, hope you can still help.

Cheers

Ken said:
For Each myObject in myCollection
If isNull(myObject.Value) And myObject.Visible = True Then
Msgbox("Field can not be null, bla bla bla")
myObject.setFocus
end if
Next
Hi there.
[quoted text clipped - 22 lines]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top