If ElseIf problem....

Stefanw

Registered User.
Local time
Today, 21:37
Joined
Jan 15, 2007
Messages
20
Hi guys,
I'm stuck in this one. I want to view some textboxes in my form, and add them into a listbox, but I need to take care of empty textboxes.
This is the code I currently use, but it only works if all textboxes are filled.
Thanks in advance...

Code:
Private Sub Form_Load()


Dim strMsg As String
Dim entity1 As String
Dim entity2 As String
Dim entity3 As String
Dim entity4 As String
Dim entity5 As String
Dim test1 As String


entity1 = Forms!Clients!entity1
entity2 = Forms!Clients!entity2
entity3 = Forms!Clients!entity3
entity4 = Forms!Clients!entity4
entity5 = Forms!Clients!entity5




If IsNull(entity1) Then
    
    Me!test = "1 is empty"
    
    ElseIf IsNull(entity2) Then
    Set lst2 = Me!lijst


    With lst2
    .RowSourceType = "Value List"
    .AddItem entity1
    .ColumnCount = 1
    End With
    
ElseIf IsNull(entity3) Then
    
    Set lst3 = Me!lijst
    
    With lst3
    .RowSourceType = "Value List"
    .AddItem entity1
    .AddItem entity2
    .ColumnCount = 1
    End With
    Me!test = "3 is leeg"

    
    
  ElseIf IsNull(entity4) Then
    Set lst4 = Me!lijst
    
    With lst4
    .RowSourceType = "Value List"
    .AddItem entity1
    .AddItem entity2
    .AddItem entity3
    .ColumnCount = 1
    End With
    Me!test = "4 is leeg"

    
    ElseIf IsNull(entity5) Then
    
    Set lst5 = Me!lijst
    With lst5
    .RowSourceType = "Value List"
    .AddItem entity1
    .AddItem entity2
    .AddItem entity3
    .AddItem entity4
    .ColumnCount = 1
    End With
    Me!test = "5 is leeg"
    
    
    Else
    Set lst6 = Me!lijst
    
    With lst6
    .RowSourceType = "Value List"
    .AddItem entity1
    .AddItem entity2
    .AddItem entity3
    .AddItem entity4
    .AddItem entity5
    .ColumnCount = 1
    End With
    Me!test = "all filled"
    
    
End If





End Sub

Please can someone help me?!
Stefan
 
You are testing for a Null field but not a ZeroLengthString. Try:
If Len(entity1 & "") = 0 Then
...and it will test for both conditions.
 
doesn't work

Nope,

isn't working at all now.

Please help me with this one,

thanks a lot:



Code:
Private Sub Form_Load()


Dim strMsg As String
Dim entity1 As String
Dim entity2 As String
Dim entity3 As String
Dim entity4 As String
Dim entity5 As String
Dim test1 As String


entity1 = Forms!Clients!entity1
entity2 = Forms!Clients!entity2
entity3 = Forms!Clients!entity3
entity4 = Forms!Clients!entity4
entity5 = Forms!Clients!entity5


'Set lst2 = Me!lijst


If Len(entity1 & "") = 0 Then
test.Visible = False

    ElseIf Len(entity2 & "") = 0 Then
    Set lst2 = Me!lijst

ElseIf Len(entity3 & "") = 0 Then
    Set lst3 = Me!lijst
    
  ElseIf Len(entity4 & "") = 0 Then
   Set lst4 = Me!lijst
 
    ElseIf Len(entity5 & "") = 0 Then
    
    Set lst5 = Me!lijst
      
      Else
    Set lst6 = Me!lijst
    
    
End If

With lst2
    .RowSourceType = "Value List"
    .AddItem entity1
    .ColumnCount = 1
    End With


    
    With lst3
    .RowSourceType = "Value List"
    .AddItem entity1
    .AddItem entity2
    .ColumnCount = 1
    End With
    
     
    
    With lst4
    .RowSourceType = "Value List"
    .AddItem entity1
    .AddItem entity2
    .AddItem entity3
    .ColumnCount = 1
    End With
    
    With lst5
    .RowSourceType = "Value List"
    .AddItem entity1
    .AddItem entity2
    .AddItem entity3
    .AddItem entity4
    .ColumnCount = 1
    End With

With lst6
    .RowSourceType = "Value List"
    .AddItem entity1
    .AddItem entity2
    .AddItem entity3
    .AddItem entity4
    .AddItem entity5
    .ColumnCount = 1
    End With

End Sub
 
A string variable can't be set to Null, so you'd need to change those to variants.
 
I'm probably just a little dense here but what is the following line designed to accomplish and where is the object (lst2) defined?
Code:
Set lst2 = Me!lijst
 
ok

if only entity 1 is filled and entity 2 till 5 are empty:
Code:
ElseIf Len(entity2 & "") = 0 Then
    Set lst2 = Me!lijst

With lst2
    .RowSourceType = "Value List"
    .AddItem entity1
    .ColumnCount = 1
    End With

And if only entity1 and 2 are filled, and entity 3 till 5 are empty:

Code:
ElseIf Len(entity3 & "") = 0 Then
    Set lst3 = Me!lijst

With lst2
    .RowSourceType = "Value List"
    .AddItem entity1
    .AddItem entity2
    .ColumnCount = 1
    End With

And so on.... thanks again
 
Is lijst your ListBox? What sort of objects are lst1...lst5?
 
list

"lijst" is the name of the combobox.

I want to insert automatically into the combobox "lijst" the 5 entity's.

But if there if only 1 entity filled, then i have a combobox with just 1 entity.
And if there are 2 entity's filled, then i have a combobox with 2 entity's, and so on....

i use lst1, lst2, etc just for filling Me!lijst.


Sorry for my bad explanation...
thanks
 
Could you just as easily use lst1 with all of the "Set"'s? How about With Me!lijst? You do not have:
Option Compare Database
Option Explicit
at the top of your class module do you?
 
See if this code does what you want:
Code:
Private Sub Form_Load()

   Dim strMsg As String
   Dim entity1 As String
   Dim entity2 As String
   Dim entity3 As String
   Dim entity4 As String
   Dim entity5 As String

   entity1 = Forms!Clients!entity1
   entity2 = Forms!Clients!entity2
   entity3 = Forms!Clients!entity3
   entity4 = Forms!Clients!entity4
   entity5 = Forms!Clients!entity5

   If IsNull(entity1) Then
      Me!test = "1 is empty"
   ElseIf Len(entity2 & "") = 0 Then
      With Me.lijst
         .RowSourceType = "Value List"
         .AddItem entity1
         .ColumnCount = 1
      End With
   ElseIf Len(entity3 & "") = 0 Then
      With Me.lijst
         .RowSourceType = "Value List"
         .AddItem entity1
         .AddItem entity2
         .ColumnCount = 1
      End With
      Me!test = "3 is leeg"
   ElseIf Len(entity4 & "") = 0 Then
      With Me.lijst
         .RowSourceType = "Value List"
         .AddItem entity1
         .AddItem entity2
         .AddItem entity3
         .ColumnCount = 1
      End With
      Me!test = "4 is leeg"
   ElseIf Len(entity5 & "") = 0 Then
      With Me.lijst
         .RowSourceType = "Value List"
         .AddItem entity1
         .AddItem entity2
         .AddItem entity3
         .AddItem entity4
         .ColumnCount = 1
      End With
      Me!test = "5 is leeg"
   Else
      With Me.lijst
         .RowSourceType = "Value List"
         .AddItem entity1
         .AddItem entity2
         .AddItem entity3
         .AddItem entity4
         .AddItem entity5
         .ColumnCount = 1
      End With
      Me!test = "all filled"
   End If
End Sub
 
problem

thanks for your reply again, ruralguy... but it still won't work.

I am finding out where the problem is.

now I am just trying to let work this:

Code:
If IsNull(entity1) Then
      Me!test = "1 is empty"
      lijst.Visible = False

   Else
      With Me.lijst
         .RowSourceType = "Value List"
         .AddItem entity1
         .AddItem entity2
         .AddItem entity3
         .AddItem entity4
         .AddItem entity5
         .ColumnCount = 1
      End With
      Me!test = "all filled"
   End If

Ok, if entity 1 is NOT null, it simply displays all the items (entity's) into the combobox, an puts into Me!test, All filled. (that's ok)

Now, if entity1 IS null or empty, it simply displays the combobox(but i am putting in the code if entity1 is empty "lijst" should be invisible)
, and with nothing inside; Me!test is empty, while it should display : 1 is empty.

if i can solve just this code, I know where the problem is....


Thanks a lot again.
Stefan
 
At this point it sounds like there is something wrong with your db. I would start by doing a /decompile and then a Compact and Repair. Then see if you still have the same problem.
 

Users who are viewing this thread

Back
Top Bottom