counter wont break if true

alaric

Registered User.
Local time
Today, 16:17
Joined
Sep 6, 2004
Messages
50
I think this is an easy one for almost everyone.. except me!

I have a form wich contains 2 sets of textboxes:
txtStuden1 - txtStudent12
txtPoint1 - txtPoint12

I fill the txtStudentX boxes from a listbox, No problem so far.
now I try to cach the first empty txtStudent textbox with a counter, and this one gives me a headache.

i have tried
For i = 1 To 6
If IsNull("Me.txtStudent" & i) Then
strCursistX = ("me.txtStudent" & i)
End If
Next i​

and tried this

For i = 1 To 6
If Not IsNull(Me.Controls("txtStudent" & i)) Then
test = Me.Controls("txtStudent" & i)
Else
test = Me.Controls("txtStudent" & i)
End If
Next i​

it gives me as a result: test = "" :confused:

can someone give me a hint

thx
Al
 
aleric,

Code:
For i = 1 to 6
   If IsNull(Me.Controls("txtStudent" & CStr(i)) Then
      Me.Controls("txtStudent" & CStr(i)) = "Something from the Listbox?"
   End If
   Next i

Wayne
 
Wayne,

thx for your quick response!
It still does not work.

For i = 1 to 6
If IsNull(Me.Controls("txtStudent" & CStr(i)) Then
Me.Controls("txtStudent" & CStr(i)) = textboxX End If
Next i​

when debugging it: I counts from 1 to 6 and stops (wow)
but when counting the texboxX = "" ????

then i want to pass the variable textBoxX to a function wich moves the selected listbox item to the field with:

MoveSingleItem "lstCursist", " texboxX"​

passing it to the function works when i use fixed values. doing this with the varaible is a next step.
 
alaric,

Gotta go back to work now.

Try this.

Get your code in Design View.
Click on the left-margin on the If Statement.
A red dot will appear (this is a breakpoint).

When your code runs, it will stop here.

F8 will single-step through the code.
F5 will run to completion.

Hover the mouse over a variable to display its value.

Or View --> Immediate window and do things like:

? Me.Controls("txtStudent" & CStr(i))

which will print its value.

Explore, will check in later,
Wayne
 
Wayne,

had a nice day at work?

I changed your code a bit, because i need the return value to pass it in a function:
For i = 1 to 6
If IsNull(Me.Controls("txtStudent" & CStr(i)) Then
textboxX = Me.Controls("txtStudent" & CStr(i)) End If
Next i​
MoveSingleItem "lstCursist", " texboxX"
(or can this be done at the same time?) havent thought about that :o

Anyway, in both cases the debugging reports;
in the immediate:
? Me.Controls("txtcursist" & CStr(i))
Null​
the result is always the same for every value of (1 to 6)

I tried to think of why it gives "" in return:
I checked (again and again) my textboxes names to make SURE they are txtStudent1, txtStudent2 etc -> they are correct (otherwise the error should hav been: Cant find the field ... referred to in your expression)

funny thing is;
i expect that the line (when running ofcourse)
textboxX = Me.Controls("txtStudent" & CStr(i)) should give me something like;
textboxX = me.txtStudent1

it dazzles me. Im going to sleep now and be back tomorrow

thx
Al
 
G’day Al.

funny thing is;
i expect that the line (when running ofcourse)
textboxX = Me.Controls("txtStudent" & CStr(i)) should give me something like;
textboxX = me.txtStudent1
It is doing that except it is only doing that when Me.Controls("txtStudent" & CStr(i)) is Null.

Hope that helps.

Regards,
Chris.
 
chris,

And thats excactly what is should do, but it doesnt :(
Meaning: the loop should lookup the first empty txtStudentX textbox. ie if txtStudent1 is occupied the loop should return txtStudent2 because thats the next empty one.
but so far it only returns ""
(the txtStudent1 etc are going to be filled with values from a lsitbox, wich works when I use fixed values)

thx for thinking with me. I appriciate it

Al
 
Obviously it is not doing what you want but it is doing what it is told.

Try putting this MsgBox in the loop and see what is happening.

Code:
For i = 1 To 6
    If IsNull(Me("txtStudent" & CStr(i))) Then
        MsgBox "textboxX will now be assigned the Null in " & "txtStudent" & CStr(i)
        textboxX = Me("txtStudent" & CStr(i))
    End If
Next i
Hope that helps.

Regards,
Chris.
 
Is this correct?

if txtStudent1 is occupied the loop should return txtStudent2 because thats the next empty one.

Or do you mean?

If txtStudent1 is occupied then loop to txtStudent2 and test it for empty and so on till txtStudent6

Code:
    Dim i As Long

    For i = 1 To 6
        If IsNull(Me("txtStudent" & CStr(i))) Then
            Exit For
        End If
    Next i
    
    If i = 7 Then
        MsgBox "There are no empty text boxes."
    Else
        MsgBox "txtStudent" & CStr(i) & " is the first empty text box."
    End If
Still guessing at what you want.

Regards,
Chris.
 
Alaric,

You are NEVER assigning anything to Me.Controls("txtStudent" & CStr(i))!!

Code:
For i = 1 to 6
   If IsNull(Me.Controls("txtStudent" & CStr(i)) Then
      textboxX = Me.Controls("txtStudent" & CStr(i)) 
   End If
   Next i

Don't know what your MoveSingleItem function does, but you probably
need something like this:

MoveSingleItem "lstCursist", "txtStudent" & CStr(i)

hth,
Wayne
 
thank you all for helping me out!
Its working!

I att a screeshot, wich (hopefully) gives more clarity.

txtStudent = txtCursist (in Dutch) and are the yellow fields in the screen.
when doubleclick on the listbox (downleft) or click cmdmove, the selected item has to move to the first empty text field.
I tell you what I want when its finished: when the user finished with adding students, he can give point to these students for there performance. --> havent done anything on it yet; When done, different records (per user) have to be written into the DB. I want to do this by creating a recordset and update the table in as many students are in the form.
Hope this makes it more clear

oke thats for the background explanation/informaton;
so it should work like this:
if txtStudent1 is occupied the loop should return txtStudent2 because thats the next empty one until the user stops adding users (or list is empty)

now for the result and hint'n tips you gave me;
its now working as I planned! :)

This is what finally did the trick;
Dim i As Long
For i = 1 To 6
If IsNull(Me("txtCursist" & CStr(i))) Then
Exit For
End If
Next i
If i = 7 Then
MsgBox "Het maximale aantal cursisten is bereikt. "
End If

MoveSingleItem "lstCursist", "txtCursist" & CStr(i)​
now I can break my head on the next challenge!
:o hope I didnt use all the credits here


gr
Al
 

Attachments

  • screenshot1.JPG
    screenshot1.JPG
    82.5 KB · Views: 105
Al,

Glad to hear that it's working.

You'll never run out of credits here.

Wayne
 

Users who are viewing this thread

Back
Top Bottom