check all combo boxes for a null value

G

Guest

i am producing a survey with 40 combo boxes for multiple choice answers, all
combo boxes must be populated. At the end of the survey i have a button to
check that all questions have been answered, if there is a null i want to set
focus and display a message, the user then answers the question and checks
the survey again untill all combos are answered.
I have done this before but lost the app, please no lectures on back ups!!

thank you in advance for your help
 
G

Guest

Hi there

For each combo box on the form:

If (IsNull([Combo Box Name]) Then
MsgBox("Please learn to fill in forms.")
[Combo Box Name].SetFocus
End If

Given the fact you have 40 text boxes, you could end up with some seriously
cluttered code. To simplify things, if there are no other combo boxes on the
form other than the 40 you're concerned about, you could use the controls
collection, using a loop to iterate through the controls on the form that
have ControlType = acComboBox. Another neat trick would be to give all the
combo boxes names which begin with the same character sequence. For example,
they could be called "Question 1", "Question 2" etc. You could then iterate
through all controls that have Left(Name,8) = "Question".

Hope this helps

David
 
G

Guest

thanks DC, got the first bit but don't fancy it x40. The second part is what
i need, to cycle through the combo boxes i have, all of which need to have
values. the problem is i am not able to write it, some one gave me the code
first time around, can you help, please, please, go on, please????

David Cleave said:
Hi there

For each combo box on the form:

If (IsNull([Combo Box Name]) Then
MsgBox("Please learn to fill in forms.")
[Combo Box Name].SetFocus
End If

Given the fact you have 40 text boxes, you could end up with some seriously
cluttered code. To simplify things, if there are no other combo boxes on the
form other than the 40 you're concerned about, you could use the controls
collection, using a loop to iterate through the controls on the form that
have ControlType = acComboBox. Another neat trick would be to give all the
combo boxes names which begin with the same character sequence. For example,
they could be called "Question 1", "Question 2" etc. You could then iterate
through all controls that have Left(Name,8) = "Question".

Hope this helps

David

dogfish said:
i am producing a survey with 40 combo boxes for multiple choice answers, all
combo boxes must be populated. At the end of the survey i have a button to
check that all questions have been answered, if there is a null i want to set
focus and display a message, the user then answers the question and checks
the survey again untill all combos are answered.
I have done this before but lost the app, please no lectures on back ups!!

thank you in advance for your help
 
G

Guest

Hmmm. My VB is quite weak but I'll give it a stab.

This solution iterates through all the controls based on their name starting
with "Question". I have no idea if it will work. Please let me know!

First name all your Combo Boxes Question1 to Question40. Then use the
following code for the button click event:

Dim i As Integer
For i% = 1 To 40
If (IsNull((Me.Controls("Question" & i%))) Then
MsgBox("Where exactly did you go to school?")
Me.Controls("Question" & i%).SetFocus
Exit For
End If
Next i%

If this doesn't work, reply with the error message!

Cheers

David

dogfish said:
thanks DC, got the first bit but don't fancy it x40. The second part is what
i need, to cycle through the combo boxes i have, all of which need to have
values. the problem is i am not able to write it, some one gave me the code
first time around, can you help, please, please, go on, please????

David Cleave said:
Hi there

For each combo box on the form:

If (IsNull([Combo Box Name]) Then
MsgBox("Please learn to fill in forms.")
[Combo Box Name].SetFocus
End If

Given the fact you have 40 text boxes, you could end up with some seriously
cluttered code. To simplify things, if there are no other combo boxes on the
form other than the 40 you're concerned about, you could use the controls
collection, using a loop to iterate through the controls on the form that
have ControlType = acComboBox. Another neat trick would be to give all the
combo boxes names which begin with the same character sequence. For example,
they could be called "Question 1", "Question 2" etc. You could then iterate
through all controls that have Left(Name,8) = "Question".

Hope this helps

David

dogfish said:
i am producing a survey with 40 combo boxes for multiple choice answers, all
combo boxes must be populated. At the end of the survey i have a button to
check that all questions have been answered, if there is a null i want to set
focus and display a message, the user then answers the question and checks
the survey again untill all combos are answered.
I have done this before but lost the app, please no lectures on back ups!!

thank you in advance for your help
 
G

Guest

you little bute, you were missing a ) but i managed to spot that one and
change your charming message a little.

thank you mucho, mucho :)

David Cleave said:
Hmmm. My VB is quite weak but I'll give it a stab.

This solution iterates through all the controls based on their name starting
with "Question". I have no idea if it will work. Please let me know!

First name all your Combo Boxes Question1 to Question40. Then use the
following code for the button click event:

Dim i As Integer
For i% = 1 To 40
If (IsNull((Me.Controls("Question" & i%))) Then
MsgBox("Where exactly did you go to school?")
Me.Controls("Question" & i%).SetFocus
Exit For
End If
Next i%

If this doesn't work, reply with the error message!

Cheers

David

dogfish said:
thanks DC, got the first bit but don't fancy it x40. The second part is what
i need, to cycle through the combo boxes i have, all of which need to have
values. the problem is i am not able to write it, some one gave me the code
first time around, can you help, please, please, go on, please????

David Cleave said:
Hi there

For each combo box on the form:

If (IsNull([Combo Box Name]) Then
MsgBox("Please learn to fill in forms.")
[Combo Box Name].SetFocus
End If

Given the fact you have 40 text boxes, you could end up with some seriously
cluttered code. To simplify things, if there are no other combo boxes on the
form other than the 40 you're concerned about, you could use the controls
collection, using a loop to iterate through the controls on the form that
have ControlType = acComboBox. Another neat trick would be to give all the
combo boxes names which begin with the same character sequence. For example,
they could be called "Question 1", "Question 2" etc. You could then iterate
through all controls that have Left(Name,8) = "Question".

Hope this helps

David

:

i am producing a survey with 40 combo boxes for multiple choice answers, all
combo boxes must be populated. At the end of the survey i have a button to
check that all questions have been answered, if there is a null i want to set
focus and display a message, the user then answers the question and checks
the survey again untill all combos are answered.
I have done this before but lost the app, please no lectures on back ups!!

thank you in advance for your help
 

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