Check all lsitbox entries are filled

S

Stuart

Here is my (not working) attempt to only enable
the OKButton if all entries in col2 of the listbox
are filled with text values

More correctly, if there is a value in col1, then
there should be some value against it in col2.

Private Sub OKButton_Click()
Dim i As Integer, missing As Integer

lbDataCode.BoundColumn = 2
missing = 0
For i = 0 To lbDataCode.ListCount - 1
If lbDataCode.Value = "" Then
missing = missing + 1
End If
Next
If missing > 0 Then
'more values are required
MsgBox ("You must complete all Fields _
in Column 2, before you exit.")
OKButton.Enabled = False
Else
OKButton.Tag = "Selected"
CancelButton.Tag = ""
Me.Hide
End If
lbDataCode.BoundColumn = 1

End Sub

How do I test for 'empty' values, please?

Regards.
 
T

Tom Ogilvy

Private Sub OKButton_Click()
Dim i As Integer, missing As Integer

'lbDataCode.BoundColumn = 2
missing = 0
For i = 0 To lbDataCode.ListCount - 1
If lbDataCode.List(i,0) <> "" and _
Trim(lbDataCode.List(i,1))="" then
missing = missing + 1
End If
Next
If missing > 0 Then
'more values are required
MsgBox ("You must complete all Fields _
in Column 2, before you exit.")
OKButton.Enabled = False
Else
OKButton.Tag = "Selected"
CancelButton.Tag = ""
Me.Hide
End If
'lbDataCode.BoundColumn = 1

End Sub
 
S

Stuart

Many thanks for that.

Regards.

Tom Ogilvy said:
Private Sub OKButton_Click()
Dim i As Integer, missing As Integer

'lbDataCode.BoundColumn = 2
missing = 0
For i = 0 To lbDataCode.ListCount - 1
If lbDataCode.List(i,0) <> "" and _
Trim(lbDataCode.List(i,1))="" then
missing = missing + 1
End If
Next
If missing > 0 Then
'more values are required
MsgBox ("You must complete all Fields _
in Column 2, before you exit.")
OKButton.Enabled = False
Else
OKButton.Tag = "Selected"
CancelButton.Tag = ""
Me.Hide
End If
'lbDataCode.BoundColumn = 1

End Sub
 

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